Partager via


IXMLDOMElement

 

Represents the element object.

JScript Example

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");  
var newRoot;  
newRoot = xmlDoc.createElement("root");  
xmlDoc.documentElement = newRoot;  
WScript.Echo(xmlDoc.xml);  
  

Output

<root/>

C/C++ Example

The following C/C++ example displays the entire sample XML file (Books.xml) from its document element.

#include “msxml6.h”  
  
inline void TESTHR( HRESULT _hr )   
   { if FAILED(_hr) throw(_hr); }  
  
void XMLDOMElementSample()  
{  
    try {  
        IXMLDOMDocumentPtr docPtr;  
        IXMLDOMElementPtr ElementPtr;  
  
        //init  
        TESTHR(CoInitialize(NULL));   
        TESTHR(docPtr.CreateInstance("Msxml2.DOMDocument.6.0"));  
  
        // Load a document.  
        _variant_t varXml("books.xml");  
        _variant_t varOut((bool)TRUE);  
        varOut = docPtr->load(varXml);  
        if ((bool)varOut == FALSE)  
            throw(0);  
        ElementPtr = docPtr->documentElement;  
        MessageBox(NULL, ElementPtr->xml, _T("Document from its root"), MB_OK);  
    } catch(...)  
    {  
        MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);  
    }  
    CoUninitialize();  
}  
  

Remarks

Element nodes are among the most common objects in the XML document tree. Element nodes can have attributes associated with them. By definition, attributes are not defined as child nodes of an element and are not considered to be part of the document tree. Accordingly, the IXMLDOMElement object provides methods to make it easier to manage attributes, including methods to associate an attribute with an element and to retrieve an attribute object and the attribute value by name.

To retrieve the set of all attributes associated with an element, you can also access the attributes property, which returns an IXMLDOMNamedNodeMap collection object that contains all the element's attributes.

Requirements

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

Version-Dependent ProgID: Msxml2.DOMDocument.5.0

Versioning

Implemented in: MSXML 3.0, MSXML 6.0

See Also

getAttribute Method1
IXMLDOMNamedNodeMap
IXMLDOMElement Members
IXMLDOMText
IXMLDOMNode