0

Is there any way to process my rest of xml file despite of any fatal error like SAXParserException encountered.

I tried with DOM, SAX and Stax parser. my XML is:

<employees>
 <employee>
  <id>1</id>
  <name>abc</name>
 </employee>
 <employee>
  <id>1</id>
  <name>abc</name123>
 </employee>
 <employee>
  <id>1</id>
  <name>abc</name>
 </employee>
</employees>

I am getting XML from a external source which I need to validate As I process above xml with SAX, i will get fatal error - SAXParserException on first name of 2nd employee entity. As per my scenario, I have to read and process all employees node who are not error prone. like 1 and 3 id's employee.

mzjn
  • 48,958
  • 13
  • 128
  • 248
  • `abc` is wrong. You probably see why. – Johannes Kuhn Mar 24 '18 at 06:36
  • 4
    If you can't control the XML content to make it valid, you need to use a fault-tolerant parser, or write one yourself. This thread might help: https://stackoverflow.com/questions/44765194/how-to-parse-invalid-bad-not-well-formed-xml/44765546#44765546 – Yoav Gur Mar 24 '18 at 06:50

0 Answers0