Export (0) Print
Expand All

IXMLDOMSchemaCollection/XMLSchemaCache

Used by the schemas and namespaces properties of the IXMLDOMDocument2 interface.

The following code shows how to create XMLSchemaCache objects in Microsoft® JScript®.

var cache = new ActiveXObject("Msxml2.XMLSchemaCache.3.0");

The IXMLDOMSchemaCollection implementation in Microsoft XML Core Services (MSXML) 2.6 and 3.0 also supports the following interface through QueryInterface.

Interface

Usage

IID_EnumVARIANT

Returns an IEnumVARIANT implementation, so that the collection can be used in Microsoft Visual Basic For Each statements. Enumerates the namespace Uniform Resource Identifiers (URIs).

Return Values

E_FAIL

The attempt to modify a read-only object failed for one of the following reasons: argument is not a valid schema; invalid namespace URI; or document is not ready.

E_INVALIDARG

The parameter is incorrect.

E_OUTOFMEMORY

Out of memory.

E_POINTER

Invalid pointer.

C++ Example

#include “msxml6.h”

#define CHECK_AND_RELEASE(pInterface)  \
if(pInterface) \
   {\
pInterface->Release();\
pInterface = NULL;\
   }\

#define RELEASE(pInterface)  \
   {\
pInterface->Release();\
pInterface = NULL;\
   }\

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("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;
}


XML Resource file: samplexmldtd.xml

The example uses the following XML file.

<?xml version='1.0'?>
<COLLECTION xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <DATE dt:dt="datetime">1998-10-13T15:56:00</DATE>
  <BOOK>
    <TITLE>Lover Birds</TITLE>
    <AUTHOR>Cynthia Randall</AUTHOR>
    <PUBLISHER>Lucerne Publishing</PUBLISHER>
  </BOOK>
</COLLECTION>


Output

The example outputs the following in a message box.

urn:schemas-microsoft-com:datatypes

The IXMLDOMSchemaCollection/XMLSchemaCache object is free-threaded and can be used in multiple documents at the same time. The XML Schema document that is sent to the schema collection is cloned, and the XML Schema document remains writable. Any changes that occur in the XML Schema file after it is stored in the schema cache are not reflected in its cloned image. A single schema cache can be added to multiple schema collections, due to the creation of the cloned image.

Note Note

In MSXML, "free-threaded" means ThreadingModel='Both', and cross-thread marshalling is supported.

Implementation:

msxml3.dll, msxml2.lib (MSXML 3.0)

msxml6.dll, msxml6.lib (MSXML 6.0)

Header and IDL files:

msxml2.h, msxml2.idl, msxml6.h, msxml6.idl

Implemented in:

MSXML 3.0, MSXML 6.0

Show:
© 2014 Microsoft