Microsoft XML SDK 2.6 - XML Reference

XMLSchemaCache Object

Used by the schemas and namespaces properties on XMLDOMDocument2.

Remarks

The SchemaCache object is free-threaded and can be used in multiple documents at the same time. A single schema document can belong to multiple schema collections and will remain read-only until it is removed from all collections. Schema documents belonging to a collection must be free-threaded.

You can create a SchemaCache object in JScript as follows:

var cache = new ActiveXObject("MSXML2.XMLSchemaCache");

Or in VBScript:

Dim cache
Set cache = CreateObject("MSXML2.XMLSchemaCache");

Example

The following example shows how to build a reusable schema cache:

  1. First, load a document that references schemas via x-schema:
    var xmldoc = new ActiveXObject("MSXML2.DOMDocument");
    xmldoc.async = false;
    xmdoc.load("http://myserver/mydata.xml");
  2. Next, build a cache from the schemas loaded by your document:
    var cache = new ActiveXObject("MSXML2.XMLSchemaCache");
    cache.addCollection(xmldoc.namespaces);
  3. Now you can use this cache in another document's load method:
    var xmldoc2 = new ActiveXObject("MSXML2.DOMDocument");
    xmldoc2.async = false;
    xmldoc2.schemas = cache;
    xmldoc2.load("http://myserver/newdata.xml");

"Xmldoc2" will load much faster because the schemas are cached.

See Also

Properties, Methods, and Events