Microsoft XML SDK 2.6 - XML Reference

add Method

Adds a new schema to the schema collection, associating the given namespace URI with the specified schema.

objXMLDOMSchemaCache.add(namespaceURI, schema)

Parameters

namespaceURI
This is the namespace to associate with the specified schema. The empty string, "", will associate the schema with the empty namespace, xmlns="".

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).

schema
Specifies the schema to load. It will load it synchronously and with resolveExternals=false and validateOnParse=false. The schema parameter can also be any DOMDocument.

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.

Example

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>

See Also

Applies To: XMLSchemaCache