Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

definition Property

Returns the definition of the node in the document type definition (DTD) or schema.

[Script]

Script Syntax

var objXMLDOMNode = oXMLDOMNode.definition;
[Visual Basic]

Visual Basic Syntax

Set objXMLDOMNode = oXMLDOMNode.definition
[C/C++]

C/C++ Syntax

HRESULT get_definition(
    IXMLDOMNode **definitionNode);

Parameters

definitionNode [out, retval]
The node that contains the definition for the entity referenced.

C/C++ Return Values

S_OK
The value returned if successful.
S_FALSE
The value returned when no definition is found.
E_INVALIDARG
The value returned if the definitionNode parameter is Null.

Example

The following C/C++ example shows the retrieval of the definition property from an IXMLDOMElement.

#import "msxml3.dll"
using namespace MSXML2;

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

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

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> 

Remarks

The property is read-only. Returns the node that contains the definition for the entity referenced.

The definition property is not supported when using inline schemas. This behavior is by design because the node being referenced can be deleted or modified after the document is loaded, yielding unpredictable results.

This value depends on the value of the nodeType property.

NODE_ENTITY_REFERENCE Returns the node for the entity referenced; that is, the ENTITY element that was defined for a given ENTITYREF. Given the ENTITYREF &x;, for example, the definition property 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 property 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 property 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 property 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 World Wide Web Consortium (W3C) Document Object Model (DOM).

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

nodeType Property

Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText