Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The markup must be well-formed

First off, let me say I am a new to SAX and Java.

I am trying to read information from an XML file that is not well formed.

When I try to use the SAX or DOM Parser I get the following error in response:

The markup in the document following the root element must be well-formed.

This is how I set up my XML file:

<format type="filename" t="13241">0;W650;004;AG-Erzgeb</format>
<format type="driver" t="123412">001;023</format>
   ...

Can I force the SAX or DOM to parse XML files even if they are not well formed XML?

Thank you for your help. Much appreciated. Haythem

like image 278
Haythem Avatar asked Mar 23 '10 11:03

Haythem


People also ask

How do you fix the markup in the document following the root element must be well formed?

The markup in the document following the root element must be well-formed. This error indicates that your XML has markup following the root element. In order to be well-formed, XML must have exactly one root element, and there can be no further markup following the single root element.

What is a root element in XML?

The XML root element represents the XML document that is being mapped. The XML root element is a looping structure that contains elements and content particles that repeat in sequence until either the group data ends or the maximum number of times that the loop is permitted to repeat is exhausted.


2 Answers

Your best bet is to make the XML well-formed, probably by pre-processing it a bit. In this case, you can achieve that simply by putting an XML declaration on (and even that's optional) and providing a root element (which is not optional), like this:

<?xml version="1.0"?>
<wrapper>
    <format type="filename" t="13241">0;W650;004;AG-Erzgeb</format>
    <format type="driver" t="123412">001;023</format>
</wrapper>

There I've arbitrarily picked the name "wrapper" for the root element; it can be whatever you like.

like image 90
T.J. Crowder Avatar answered Sep 19 '22 21:09

T.J. Crowder


Hint: using sax or stax you can successfully parse a not well formed xml document until the FIRST "well formed-ness" error is encountered.

(I know that this is not of too much help...)

like image 45
Yaneeve Avatar answered Sep 21 '22 21:09

Yaneeve