Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

documentElement Property


Contains the root element of the document.

var objXMLDOMElement = oXMLDOMDocument.documentElement;  
objXMLDOMDocument.documentElement = objXMLDOMElement;  


The following script example creates an IXMLDOMElement object and sets it to the root element of the document with the documentElement property. It then walks the document tree.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
var root;
xmlDoc.async = false;
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   WScript.Echo("You have error " + myErr.reason);
} else {
   root = xmlDoc.documentElement;
   for (var i=0; i<root.childNodes.length; i++) {

Set objXMLDOMElement = oXMLDOMDocument.documentElement  
Set objXMLDOMDocument.documentElement = objXMLDOMElement   

HRESULT get_documentElement(  
    IXMLDOMElement** DOMElement);  
HRESULT putref_documentElement(  
    IXMLDOMElement* DOMElement);  


DOMElement[out, retval][in]
The IXMLDOMElement object that represents the single element representing the root of the XML document tree. Returns Null if no root exists.

C/C++ Return Values

The value returned if successful.

S_FALSE (for get_documentElementonly)
The value returned if there is no document element.

E_INVALIDARG (for get_documentElementonly)
The value returned if the DOMElement parameter is Null.

The property is read/write. It returns an IXMLDOMElement that represents the single element that represents the root of the XML document tree. It returns Null if no root exists.

When setting the documentElement property, the specified element node is inserted into the child list of the document after any document type node. To precisely place the node within the children of the document, call the insertBefore method of theIXMLDOMNode.

The parentNode property is reset to the document node as a result of this operation.

Implemented in:

MSXML 3.0, MSXML 6.0


insertBefore Method
parentNode Property1

© 2018 Microsoft