次の方法で共有


definition Property1

 

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

This property only works with DTDs and XDR schemas. This property does not work with documents that have an XSD schema.

XDR schemas are not supported in MSXML 6.0. Therefore, in MSXML 6.0 the definition property only works with documents with a DTD.

Script Syntax

var objXMLDOMNode = oXMLDOMNode.definition;  

Visual Basic Syntax

Set objXMLDOMNode = oXMLDOMNode.definition  

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

Resource Files

The C\C++ example uses the following XML files.

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

The C\C++ example outputs the following 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 "https://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).

Versioning

Implemented in: MSXML 3.0, MSXML 6.0.

Applies to

IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | IXMLDOMDocument-DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText

See Also

nodeType Property1