Used by the schemas and namespaces properties on IXMLDOMDocument2.
add | Adds a new item to a schema collection. |
addCollection | Adds all the schemas from another collection into the current collection. |
get | Returns a read-only DOM node containing the <Schema> element. |
length | Returns the number of namespaces currently in a collection. |
namespaceURI | Returns the namespace at the specified index. |
remove | Removes the specified namespaces from a collection. |
The SchemaCollection interface 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.
The IXMLDOMSchemaCollection implementation in Msxml 2.6 and 3.0 also supports the following interface via QueryInterface:
Interface | Usage |
---|---|
IID_EnumVARIANT | Returns an IEnumVARIANT implementation so the collection can be used in Visual Basic For…Each statements. Enumerates the namespace URIs. |
BOOL DOMDocument2nameSpaces() { BOOL bResult = FALSE; short sResult = FALSE; IXMLDOMElement *pIXMLDOMElement=NULL; IXMLDOMSchemaCollection *pIXMLDOMSchemaCollection=NULL; IXMLDOMDocument2 *pIXMLDOMDocument2=NULL; HRESULT hr; BSTR bstrValue; try { hr=CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_SERVER, IID_IXMLDOMDocument2, (LPVOID*)(&pIXMLDOMDocument2)); SUCCEEDED(hr) ? 0 : throw hr; if(pIXMLDOMDocument2) { hr=pIXMLDOMDocument2->put_async(VARIANT_FALSE); if(SUCCEEDED(hr)) { hr=pIXMLDOMDocument2->load(_variant_t( _T("d:\\inetpub\\wwwroot\\samplexmldtd.xml")), &sResult); if(SUCCEEDED(hr) && (sResult==VARIANT_TRUE)) { hr=pIXMLDOMDocument2->get_namespaces( &pIXMLDOMSchemaCollection); if(SUCCEEDED(hr)) { LONG uLength; bResult=TRUE; hr=pIXMLDOMSchemaCollection->get_length(&uLength); if(SUCCEEDED(hr)) { for(int iIndex=0; iIndex < uLength; iIndex++) { hr=pIXMLDOMSchemaCollection->get_namespaceURI( iIndex, &bstrValue); if(SUCCEEDED(hr)) ::MessageBox(NULL, bstrValue, _T("Namespace"), MB_OK); } } } } } RELEASE(pIXMLDOMDocument2); } } catch(...) { CHECK_AND_RELEASE(pIXMLDOMDocument2); DisplayErrorToUser(); } return bResult; }
d:\\inetpub\\wwwroot\\samplexmldtd.xml
<?xml version='1.0'?> <COLLECTION 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> </COLLECTION>
Output (in a message box)
urn:schemas-microsoft-com:datatypes
Implementation: Msxml2.dll
Header and IDL files: Msxml.h, Xmldom.idl
Version-Independent ProgID: Msxml2.XMLSchemaCache
Version-Independent CLSID: 373984C9-B845-449B-91E7-45AC83036ADE
Version-Dependent ProgID: Msxml2.XMLSchemaCache.2.6
Version-Dependent CLSID: f5078f1d-c551-11d3-89b9-0000f81fe221