Example 1: Validating with noNamespaceSchemaLocation (Visual Basic)


The xsi:noNamespaceSchemaLocation attribute is an XML schema instancing (XSI) attribute you can use when the XML document you want to validate does not use namespaces for some or all of its contents.

When used, the xsi:noNamespaceSchemaLocation attribute suggests a single URL to the XML processor to locate an XSD schema file for validating nodes that are untargeted (i.e. not prefixed by a namespace).


Even when you use an xsi:noNamespaceSchemaLocation attribute in a document, there is a possibility that in some cases MSXML can 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 referenced in this value.

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

This project uses the following files.