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

IXMLDOMElement

Represents the element object.

[Script]

Example

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var newRoot;
newRoot = xmlDoc.createElement("root");
xmlDoc.documentElement = newRoot;
alert(xmlDoc.xml);
[Visual Basic]

Example

Dim xmlDoc As New Msxml2.DOMDocument50
Dim newRoot As IXMLDOMElement
Set newRoot = xmlDoc.createElement("root")
Set xmlDoc.documentElement = newRoot
MsgBox xmlDoc.xml
[C/C++]

Example

The following C/C++ example displays the entire XML document from its root element.

#import "msxml5.dll"
using namespace MSXML2;

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.5.0"));

      // Load a document.
      _variant_t varXml("C:\\book.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.

Versioning

MSXML 2.0 and later

Requirements

Implementation: msxml5.dll, msxml2.lib

[C/C++]

Header and IDL files: msxml2.h, msxml2.idl

Version-Dependent ProgID: Msxml2.DOMDocument.5.0

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

getAttribute Method | IXMLDOMNamedNodeMap | IXMLDOMElement Members | IXMLDOMText | IXMLDOMNode