Validate an XML Document or Fragment (JScript)

 

[This sample code uses features that were first implemented in MSXML 5.0 for Microsoft Office Applications.]

In MSXML 5.0 for Microsoft Office Applications and later, there are two ways to validate XML data against a set of XML Schema definitions. One uses the validate method on an XML DOM instance to validate the entire DOM object. The other uses the validateNode(node) method on a DOM instance to validate a DOM fragment. A DOM fragment is a sub-tree rooted at the specified node.

The example in this tutorial illustrates both of these methods. This project uses the following files.

Component Description
Source: validateDOM.js Validates an XML file against an XSD schema.
Resource: books.xml and books.xsd An XML data file and an XSD schema file.
Output When you build and run the validateDOM project, you should get this output in a console window.

To create the validateDOM JScript project

  1. Create a JScript project. For detailed instructions on how to do this, see Set Up My JScript Project.

  2. Name the project folder validateDOMProj.

Next, we'll add the source code for this project.