简体   繁体   English

为什么这个xml没有很好地形成?

[英]Why is this xml not well formed?

I keep getting an error saying that the xml is not well formed. 我一直收到一个错误,说xml没有很好地形成。 I have tried looking at all the other posts on this website about xml not being well formed and non of them seem to answer my question. 我已经尝试查看本网站上所有其他帖子关于xml没有很好的形成,他们似乎没有回答我的问题。 Here is the xml code. 这是xml代码。 If providing the DTDs are necessary let me know and I'll post it. 如果提供DTD是必要的,请告诉我,我会发布。 The line with the error is marked. 标有错误的行。

<story category="national" byline="Karen Wheatley">
   <headline>President Meets with Congress</headline>
   <synopsis><![CDATA[
               The President meet with Congressional leaders today in effort to jump-start
               faltering budget negotiations. Sources described the mood of the meeting
               as "cordial".
               ]]>
   </synopsis>
   <article ref="news801" />
   <image src="img2071" />
</story>
<story category="international">  <!--Error is here!.-->
   <headline>Relief Agencies head to Peru</headline>
   <synopsis><![CDATA[
               Relief agencies headed to Peru today in wake of yesterday's massive earthquake.
               Initial casualty estimates top 8000, in what would be one of the most
               devasting earthquakes in the last 5 years.
               ]]>
   </synopsis>
   <article ref="news802" />
   <image src="img2072" />
   <image src="img2073" />
</story>
<story category="national" byline="Andrew Browne">
   <headline>Congress Approves Judicial Nominee</headline>
   <synopsis><![CDATA[
               By a vote of 55-42, the Senate approved controversial judge Sandra Lehman
               to the bench of the third circuit court.
               ]]>
   </synopsis>
   <article ref="news803" />
   <image src="img2074" />
</story>
<story category="sports">
   <headline>Bucks grab Series Lead</headline>
   <synopsis><![CDATA[
                Last night, the Milwaukee Bucks defeated the Los Angles Lakers to take a 
                3-2 lead in the NBA finals. The series returns to Los Angeles tomorrow night,
                where the Lakers have been undefeated in the playoffs.
               ]]>
   </synopsis>
   <article ref="news804" />
   <image src="img2075" />
</story>
<story category="entertainment" byline="Chandra Parks">
   <headline>"The Witness" tops Box Office</headline>
   <synopsis><![CDATA[
                "The Witness" was the top-ranked movie this week with 18M in sales. Last week's
                box champ, "Another Life", fell to second with 11M in sales.
               ]]>
   </synopsis>
   <article ref="news805" />
</story>

An XML document must have a exactly one root element. XML文档必须只有一个根元素。

You start with a <story> , close it, and then start another one. 你从一个<story> ,关闭它,然后开始另一个。

It is not well-formed because it has multiple top-level elements <story> . 它的格式不正确,因为它有多个顶级元素<story>

To make it well-formed you would need to wrap the entire file with, for example 为了使其格式良好,您需要使用例如包装整个文件

<stories>
    .. your file
</stories>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM