Adds a new schema to the schema collection, associating the given namespace URI with the specified schema.
objXMLDOMSchemaCache.add(namespaceURI, schema)
This may be any string that can be used in an xmlns attribute, but it cannot contain entity references. The same whitespace normalization that occurs on the xmlns attribute also occurs on namespaceURI (that is, leading and trailing white space is trimmed, new lines are converted to spaces, and multiple adjacent white space characters are collapsed into one space).
This argument can be Null, which results in the removal of any schema for the specified namespaces. If the schema is an XMLDOMNode, the entire document the node belongs to will be preserved.
The following Visual Basic sample attaches a schema to an xml document:
Dim xslDoc As New MSXML2.FreeThreadedDOMDocument Dim SchemaCache 'Create the collection. Set SchemaCache = CreateObject("Msxml2.XMLSchemaCache") SchemaCache.Add "x-schema:books.xml", "d:\\inetpub\\wwwroot\\bookschema.xml" 'This Schema Cache can be attached to multiple documents. Set xslDoc.schemas = SchemaCache xslDoc.async = False 'The document will load only if a valid schema is attached to the xml 'file. xslDoc.Load "http://sampleserver/samplexmldtd.xml" MsgBox xslDoc.xml
http://sampleserver/samplexmldtd.xml
<?xml version='1.0'?> <COLLECTION xmlns="x-schema:books.xml" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <DATE dt:dt="datetime">1998-10-13T15:56:00</DATE> <BOOK> <TITLE>Cosmos</TITLE> <AUTHOR>Carl Sagan</AUTHOR> <PUBLISHER>Ballantine Books</PUBLISHER> </BOOK> <BOOK> <TITLE>Catwings</TITLE> <AUTHOR>Ursula K. Le Guin</AUTHOR> <PUBLISHER>Scholastic</PUBLISHER> </BOOK> </COLLECTION>
d:\inetpub\wwwroot\bookschema.xml
<?xml version="1.0"?> <Schema xmlns="urn:schemas-microsoft-com:xml-data"> <ElementType name="TITLE"/> <ElementType name="AUTHOR"/> <ElementType name="PUBLISHER"/> <ElementType name="DATE"/> <ElementType name="BOOK" model="closed"> <element type="TITLE"/> <element type="AUTHOR"/> <element type="PUBLISHER"/> </ElementType> <ElementType name="COLLECTION" model="closed"> <element type="BOOK"/> </ElementType> </Schema>
Output (in a message box)
<?xml version='1.0'?> <COLLECTION xmlns="x-schema:books.xml" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <DATE dt:dt="datetime">1998-10-13T15:56:00</DATE> <BOOK> <TITLE>Cosmos</TITLE> <AUTHOR>Carl Sagan</AUTHOR> <PUBLISHER>Ballantine Books</PUBLISHER> </BOOK> <BOOK> <TITLE>Catwings</TITLE> <AUTHOR>Ursula K. Le Guin</AUTHOR> <PUBLISHER>Scholastic</PUBLISHER> </BOOK> </COLLECTION>
Applies To: XMLSchemaCache