The markup should be well formed

First of all, let me say that I am new to SAX and Java.

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

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

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 get SAX or DOM to parse XML files, even if they are poorly formed XML?

Thank you for your help. Very grateful. Haythem

+7
java xml sax
source share
3 answers

It is best to make XML valid, perhaps by pre-processing it. In this case, you can achieve this by simply adding an XML declaration (and even this is optional) and providing a root element (which is not optional), for example:

 <?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 arbitrarily chose the name "wrapper" for the root element; that could be all you like.

+18
source share

Hint: Using sax or stax, you can successfully parse a malformed XML document until you encounter a FIRST error.

(I know this doesn't help much ...)

+1
source share

When the DOM scans your XML file, then create a tree, the root of the tree node will be like 1 answer. However, if Parser cannot find or even, he can even build a tree. Thus, it is better to do some preprocessing of the xml file before its DOM or Sax parser.

0
source share

All Articles