Microsoft XML SDK 2.6 - XML Reference

IXMLDOMNode::definition Method

IXMLDOMNode::get_definition Method

Returns the definition of the node in the DTD or schema.

Visual Basic Syntax

Set objXMLDOMNode = oXMLDOMNode.definition

C/C++ Syntax

HRESULT get_definition(
    IXMLDOMNode **definitionNode);

Parameters

definitionNode [out]
Node that contains the definition for the entity referenced.

C/C++ Return Values

S_OK
Value returned if successful.
S_FALSE
Value returned when no definition is found.
E_INVALIDARG
Value returned if definitionNode is Null.

Remarks

This value depends on the value of the nodeType method.

The definition method is not supported when using in-line schemas. This behavior is by design because the node being referenced may be deleted or modified after the document is loaded, which would yield unpredictable results.

NODE_ENTITY_REFERENCE Returns the node for the entity referenced; that is, returns the ENTITY element that was defined for a given ENTITYREF. Given the ENTITYREF &x;, for example, the definition method returns the node in the DOCTYPE node's entity collection that defines the corresponding ENTITY: <!ENTITY x "y">.
NODE_ENTITY For unparsed entities, returns the NOTATION definition from the DOCTYPE node's notation collection. For example, given the ENTITY <!ENTITY networth SYSTEM "networth.xls" NDATA XLS>, the definition method returns the node corresponding to the notation <!NOTATION XLS PUBLIC "http://www.microsoft.com/office/excel/">. For parsed entities, returns Null.
NODE_ATTRIBUTE Returns the XML-Data Schema AttributeType for a given ATTRIBUTE node. For example, the definition method for the attribute myAttribute="123" returns the node corresponding to the element <AttributeType name="myAttribute"> in the schema. Returns Null when a DTD is used or when no schema is present.
NODE_ELEMENT Returns the XML-Data Schema ElementType for a given ELEMENT node. For example, given the element <myelement>, the definition method returns the node <ElementType name="myelement"> in the specified external schema. Returns Null when a DTD is used or when no schema is present.
NODE_CDATA_SECTION, NODE_COMMENT, NODE_DOCUMENT, NODE_DOCUMENT_FRAGMENT, NODE_DOCUMENT_TYPE, NODE_NOTATION, NODE_PROCESSING_INSTRUCTION, NODE_TEXT Returns Null.

This member is an extension of the W3C DOM.

Example

The following example demonstrates retrieval of the definition method from an XMLDOMElement:

BOOL DOMNodeGetDefinition()
{
   BOOL bResult = FALSE;
   BSTR bstrValue;
   IXMLDOMElement *pIXMLDOMElement = NULL;
   IXMLDOMNode *pIXMLDOMNode = NULL;
   IXMLDOMDocument2 *pIXMLDOMDocument = NULL;
   HRESULT hr;

   try
   {
      // Create the document and initialize pIXMLDOMDocument.
      // Load the document (sample.xml).
      // Get the documents root.
      hr = pIXMLDOMDocument->get_documentElement(&pIXMLDOMElement);
      SUCCEEDED(hr) ? 0 : throw hr;

      if(pIXMLDOMElement)
      {
         hr = pIXMLDOMElement->get_definition(&pIXMLDOMNode);
         if(SUCCEEDED(hr) && pIXMLDOMNode)
         {
            hr = pIXMLDOMNode->get_xml(&bstrValue);
            if(SUCCEEDED(hr) && bstrValue)
            {
               ::MessageBox(NULL, bstrValue, _T("Definition"), MB_OK);
               ::SysFreeString(bstrValue);
               bResult = TRUE;
            }
            RELEASE(pIXMLDOMNode);
         }
         RELEASE(pIXMLDOMElement);
      }
   }
   catch(...)
   {
      if(bstrValue)
         ::SysFreeString(bstrValue);
      CHECK_AND_RELEASE(pIXMLDOMNode);
      CHECK_AND_RELEASE(pIXMLDOMElement);
      // Release the DOMDocument.
      DisplayErrorToUser();
   }
   // Release the document when finished with it.
   return bResult;
}

Sample.xml

<?xml version="1.0"?> 
<SomeDoc xmlns="x-schema:collschema.xml"> 
   <SomeElement Id="first1"> 
   </SomeElement> 
</SomeDoc> 

collschema.xml

<?xml version='1.0'?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data" 
       xmlns:dt="urn:schemas-microsoft-com:datatypes"> 
   <AttributeType name='Id' dt:type="id"/> 
   <ElementType name='SomeElement' content="mixed" model="open"> 
      <attribute type='Id'/> 
   </ElementType> 

   <ElementType name='SomeDoc' content="mixed" model="open"> 
      <attribute type='Id'/> 
      <element type='SomeElement' minOccurs='1' maxOccurs='*'/> 
   </ElementType> 
</Schema> 

Output (in a message box)

<ElementType name='SomeDoc' content="mixed" model="open"> 
   <attribute type='Id'/> 
   <element type='SomeElement' minOccurs='1' maxOccurs='*'/> 
</ElementType> 

See Also

IXMLDOMNode Interface