Question

I have a problem with a SAX xml parser. I want to parse a xml file which obviously is not valid (I get an ExpatParser$ParseException: At line 5, column 169: not well-formed (invalid token)). I know what is wrong, but the xml file ist not created by me...so I cant change it.

Now I want to handle that Error in my DefaultHandler. But neither error() nor fatalError() nor warning() is invoked...

Can I somehow interrupt the parsing process, tell the parser what to do with that piece of invalid xml and continue parsing???

Thanks, JPM

Was it helpful?

Solution

I would guess that this SAXParseException is a fatal error that the SAX parser cannot recover from. In that case you probably need to fix up the bad tag before trying to parse it (as Robert suggests in his comment).

You might want to look into using a Java Regex to fix up the known badness in the XML, e.g.
Regex for quoting unquoted XML attributes

For the record, I am not advocating using regex to actually parse XML!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top