Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I parse broken XML files in Java? [duplicate]

Tags:

java

xml

I'm receiving XML files from an external source over which I have no control. Some of the XML files are broken. Specifically, towards the end of the file, some closing tags are missing. It goes something like this:

<?xml version="1.0" encoding="UTF-8" ?>
<a>
  <b>
    <c/>
  </b>
  <b>
    <c/>
</a>

I think our system will be fine if we simply ignore the elements that don't have a matching closing tag.

What library can I use to parse what I can from such XML files?

like image 458
Steve McLeod Avatar asked Dec 05 '25 19:12

Steve McLeod


1 Answers

You will need to manually parse it yourself, no XML parser will work on XML that's not well formed. One possibility is to use a SAX parser, it will parse the document up to the error then stop.

like image 114
Rocky Pulley Avatar answered Dec 08 '25 07:12

Rocky Pulley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!