Example 2: Validating with schemaLocation (JScript)


The xsi:schemaLocation attribute is an XML schema instancing (XSI) attribute you can use when the XML document you want to validate uses or declares a namespace.

This attribute provides a two-part hint to the XML processor to help it locate an XSD schema file for any nodes that are prefixed with "x:" where the namespace resolves to and matches a namespace URI ("urn:books").


Even when you use an xsi:schemaLocation attribute in a document, in some cases MSXML might disregard its use in the actual validation process. This can happen if the XSD schema file referenced is itself not valid or if it cannot be found. MSXML can also be configured to use a cached schema instead and ignore the schema file referred to in this value.

In the following example, we will create two versions of an XML sample resource file (sl-valid.xml and sl-notValid.xml) to be validated against a schema file named sl.xsd. The two XML files are nearly identical, with only one slight difference: the <x:price> element in sl-valid.xml, which is declared in the schema, has been replaced with an undeclared <x:cost> element in sl-notValid.xml.

This project uses the following files.