• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 926
  • Last Modified:

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

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,
  • 2
1 Solution
Most tools stop after the first error...

This tool is reported to outline all errors:


available online: http://www.w3.org/2001/03/webdata/xsv

win32 installer: ftp://ftp.cogsci.ed.ac.uk/pub/XSV/XSV210.EXE

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


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now