Search code examples
c++visual-studioxml-parsingxmllite

XML Lite parsing issue - ignore invalid data when parsing


I use XML Lite from microsoft (http://msdn.microsoft.com/en-us/library/windows/desktop/ms752872%28v=vs.85%29.aspx)

Is there a way to ignore any validation errors it might do(I get some obscure error on a node related to "" - although the XML input seems just fine) and just continue with next nodes ?

I have the reading loop like this

while ( !reader->IsEOF())
{
        result = reader->Read(&nodeType);
        if (result != S_OK)
        {
            //just ignore cuurrent read and continue reading more from XML
            continue; // does not work
        }

Solution

  • What is the error code returned by XmlLite? Invalid characters? XmlLite is a W3C compliant XML parser, meaning that it is by design to choke on invalid XML files with invalid characters, and there is not such a feature to ignore invalid character and move on. The options are:

    1. Use XmlLite or other compliant XML parser to generate the XML. In this way you won't get invalid character at the first place.
    2. Filter out invalid characters if you have control of the source data. XmlLite supports XML 1.0, with a range of valid character as #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF].

    Other than that, XmlLite probably may not be your choice.