Example 3: Validating with XMLSchemaCache (Visual Basic)


In addition to using the XML Schema instancing (XSI) attributes, MSXML enables you to connect and use an XMLSchemaCache object to validate documents to XSD schemas.

Caching the XSD schema is a good approach to use when you:

  • Want to override the use of other XSD schemas specified in either the schemaLocation or noNamespaceSchemaLocation attributes.

  • Need to use the same XSD schema repeatedly to validate and process a number of documents of the same XML document type.

  • Want to increase performance by loading and caching the XSD schema once, instead of repeatedly loading it with each XML document.

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

We've provided source files for the sample in three languages: JScript, Visual Basic, and C++. The output is the same in each language.