How to handle XML parsing exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AliRezaGoogle

    How to handle XML parsing exception

    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
  • Jon Skeet [C# MVP]

    #2
    Re: How to handle XML parsing exception

    On Aug 7, 2:10 pm, AliRezaGoogle <asemoo...@yaho o.comwrote:
    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

    Comment

    • Marc Gravell

      #3
      Re: How to handle XML parsing exception

      How can I overcome this bug?

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

      Marc

      Comment

      • MC

        #4
        Re: How to handle XML parsing exception

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

        But his request is reasonable. Corrupted XML files do occur. 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)

        or even

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

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


        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: How to handle XML parsing exception

          On Aug 7, 2:47 pm, "MC" <for.address.l. ..@www.ai.uga.e du.slash.mc>
          wrote:
          It sounds like the "bug" is your malformed xml. Fix your pseudo-xml.
          >
          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>qwer tyuiop</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

          Comment

          Working...