문제

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

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top