How do I validate XML document against an XML schema and get ALL parsing errors returned?

Posted on 2007-07-23
Last Modified: 2013-11-17
I am using XML DOM to validate an XML document against an XML schema.  However, it only returns the first parsing error found.  The XML is well-formed so I'm not interested in these kind of errors, only errors where the data doesn't conform to the schema provided.  Is there any way (using XML DOM or otherwise) to have it return all errors within the document, or provide a means of iterating through them - without correcting each error in between, of course?  To put this into perspective, this is the code I currently have.

    IXMLDOMSchemaCollectionPtr  pXS;
    IXMLDOMDocument2Ptr         pXD;

    // Create a schema cache and add the XML schema to it
    HRESULT hr = pXS.CreateInstance(__uuidof(XMLSchemaCache60));
    hr = pXS->add(_T(""), _T("C:\\MySchema.xsd");

    // Create a DOMDocument and set its properties
    hr = pXD.CreateInstance(__uuidof(DOMDocument60));
    pXD->async = VARIANT_FALSE;
    pXD->validateOnParse = VARIANT_TRUE;
    pXD->resolveExternals = VARIANT_TRUE;

    // Assign the schema cache to the DOMDocument's schemas collection
    pXD->schemas = pXS.GetInterfacePtr();

    // Load the XML document data file as the DOM document
    hr = pXD->load(_T("C:\\MyData.xml"));

    MSXML2::IXMLDOMParseErrorPtr pErr = pXD->parseError;

    // Return validation results in message to the user
    if (FAILED(pErr->errorCode))
        _tprintf(_T("\nValidation failed\n=================\n")
                 _T("Reason: %s\nSource: %s\nLine: %i\n"),
        _tprintf(_T("\nValidation succeeded\n====================\n%s"),

Many thanks,
Question by:Xtreem
    LVL 13

    Accepted Solution

    Most tools stop after the first error...

    This tool is reported to outline all errors:

    available online:

    win32 installer:

    Good luck.
    LVL 13

    Expert Comment

    This thread outlines various IDEs, etc that can 'find all errors' at once

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now