繁体   English   中英

Java XML 问题:文档中根元素后面的标记必须格式正确

[英]Java XML Problem: The markup in the document following the root element must be well-formed

我收到此错误: [Fatal Error] Adverts.xml:26:2: The markup in the document following the root element must be well-formed. org.xml.sax.SAXParseException; systemId: file:/C:/Users/NULL/Desktop/Adverts.xml; lineNumber: 26; columnNumber: 2; The markup in the document following the root element must be well-formed. [Fatal Error] Adverts.xml:26:2: The markup in the document following the root element must be well-formed. org.xml.sax.SAXParseException; systemId: file:/C:/Users/NULL/Desktop/Adverts.xml; lineNumber: 26; columnNumber: 2; The markup in the document following the root element must be well-formed.

我已经谷歌研究了它并试图弄清楚我可能做错了什么。 不过我不知道。 XML 文件如下:

    <advertisement>
    <server name="Zenith"> 
    <discordlink>http://zenithps.org</discordlink>
    <ownerid>304558905306906624</ownerid>
    <logourl>http://zenithps.org/Zenith%20Logo.png</logourl>
    <feature>Feature1</feature>
    <feature>Feature2</feature>
    <image>C:/Users/NULL/Pictures/Zenith Logo.png</image>
    <image>C:/Users/NULL/Pictures/Description Hovers.gif</image>
    <image>C:/Users/NULL/Pictures/Launcher.png</image>
    <image>C:/Users/NULL/Pictures/Upgrade.gif</image>
    <image>C:/Users/NULL/Pictures/Pet.png</image>
    </server>

    <guild id="642406906580828181">
    <name>Guild</name>
    <advertchannel>658936539803418624</advertchannel>
    <commandchannel>658936539803418624</commandchannel>
    <user>304558905306906624</user>
    <delay>25000</delay>
    </guild>

    </advertisement>


    <advertisement>
    <server name="Test Server"> 
    <discordlink>http://zenithps.org</discordlink>
    <ownerid>304558905306906624</ownerid>
    <logourl>http://zenithps.org/Zenith%20Logo.png</logourl>
    <feature>Feature1</feature>
    <feature>Feature2</feature>
    <image>C:/Users/NULL/Pictures/Zenith Logo.png</image>
    <image>C:/Users/NULL/Pictures/Description Hovers.gif</image>
    <image>C:/Users/NULL/Pictures/Launcher.png</image>
    <image>C:/Users/NULL/Pictures/Upgrade.gif</image>
    <image>C:/Users/NULL/Pictures/Pet.png</image>
    </server>

    <guild id="6424069110828181">
    <name>Test Guild</name>
    <advertchannel>658936539803418624</advertchannel>
    <commandchannel>658936539803418624</commandchannel>
    <user>304558905306906624</user>
    <delay>25000</delay>
    </guild>

    </advertisement>

错误发生在文件的第二个大约一半处,就在上面

<server name="Test Server"> 

知道我做错了什么,我仍然是非常新的 XML(这是我解析的第一个 XML 文件),但我看不出任何错误。

一个 XML 文档中不能有多个根元素,才能使其格式正确。

你要么必须

  1. 拆分文件,或
  2. 将整个内容包装在一个新的根元素中,例如

    <advertisements> <advertisement> <!-- ... --> </advertisement> <advertisement> <!-- ... --> </advertisement> </advertisements>

每个 XML 文档只有一个根元素。

https://en.wikipedia.org/wiki/Root_element

暂无
暂无

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

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