Menu

Error handling when parsing strings

John Dunn
2007-05-04
2013-05-20
  • John Dunn

    John Dunn - 2007-05-04

    I'm having problems getting useful error messages parsing an XML document from a string. I've tried both TiXmlDocument.Parse and istringstring >> TiXmlDocument.

    If I pass in invalid XML data I get the following results

    Parse()
      doc.Error() = true
      doc.ErrorDesc = Error document empty.
      doc.ErrorId = 13

    >> TiXmlDocument
      doc.Error() = true
      doc.ErrorDesc = null
      doc.ErrorId = 13

    Is there any way to get useful error messages out of the library?

     
    • Lee Thomason

      Lee Thomason - 2007-05-06

      Do you mean it works with "Parse()" but not ">>" ?

      lee

       
    • John Dunn

      John Dunn - 2007-05-10

      I've gone back and attempted to reproduce the case where the stream operator was not giving my a valid ErrorDesc() but unfortunately I didn't save it.

      I think some of my confusion was due to the ErrorDesc itself. I was parsing a string that looks like "aaa<test></test>" and did not expect an error message of "Error document empty." - I was hoping for something a little more descriptive. For example, IE gives the following error -

        Invalid at the top level of the document.

      and Firefox gives-

        XML Parsing Error: not well-formed

      both of which I find more helpful than the TinyXML error.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.