How to handle XML parsing exception

  • Thread starter Thread starter AliRezaGoogle
  • Start date Start date
A

AliRezaGoogle

Dear Members

When I tried to navigate in an XML file, an exception occurred :
"An error occurred while parsing XML file".

I want to ignore the case (line(s)) which caused the exception and
continue navigating, but unfortunately xmlreader.Read() does not work.
It seems that the xmlreader object hangs. How can I overcome this bug?

Thanks in advance
 
When I tried to navigate in an XML file, an exception occurred :
"An error occurred while parsing XML file".

I want to ignore the case (line(s)) which caused the exception and
continue navigating, but unfortunately xmlreader.Read() does not work.
It seems that the xmlreader object hangs. How can I overcome this bug?

As far as I'm aware, you can't - malformed XML is basically fatal to
XML parsers which aren't designed to compensate (e.g. for text
editors).

Is there any reason you can't fix the XML first instead?

Jon
 
How can I overcome this bug?

It sounds like the "bug" is your malformed xml. Fix your pseudo-xml.

Marc
 
But his request is reasonable.  Corrupted XML files do occur.

Indeed, and the data in them shouldn't be trusted.
The syntax of XML should make it possible to recover (partly) from minor corruption, e.g.,
change

<blither><blah>asdfasdf</blaaaaah><blah>qwertyuiop</blah></blither>

into

<blither><blah>qwertyuiop</blah></blither>
(omitting the malformed section)

Except there are any number of alternative ways of "recovering" from
the error, and no way of knowing which one is "correct".

XML was specifically designed to be error intolerant, partly to avoid
all the error recovery which has plagued browsers.
or even

<blither><blah>asdfasdf</blah><blah>qwertyuiop</blah></blither>
(correcting the incorrect terminator).

So who will invent a syntax-error-tolerant XML parser?

They must exist for text editors etc - but I wouldn't want to use one
for anything where the XML is being actually processed instead of just
displayed to a user.

Jon
 
Back
Top