简体   繁体   中英

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

I'm receiving this error: [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.

I have google researched it and tried too figure what I may be possibly doing wrong. However I have no idea. The XML file goes as such:

    <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>

The error occurs on the second roughly half way through the file, just above

<server name="Test Server"> 

Any idea what I'm doing wrong, I'm still very new XML(this being the first XML file I've parsed) but I cannot see anything wrong.

You cannot have multiple root elements in one XML document for it to be well-formed.

You would either have to

  1. split up the document, or
  2. wrap the entire contents in a new root element, eg

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

Each XML document has exactly one single root element.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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