parentNode Property
Contains the parent node.
Script Syntax
var objXMLDOMNode = oXMLDOMNode.parentNode;
Example
The following script example obtains a reference to the IXMLDOMNode
object that is another node object's parent and displays its XML.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); var currNode; var newNode; xmlDoc.async = false; xmlDoc.load("books.xml"); if (xmlDoc.parseError.errorCode <> 0) { var myErr = xmlDoc.parseError; alert("You have error " + myErr.reason); } else { currNode = xmlDoc.documentElement.childNodes.item(1).childNodes.item(0); newNode = currNode.parentNode; alert(newNode.xml); }
Visual Basic Syntax
Set objXMLDOMNode = oXMLDOMNode.parentNode
Example
The following Microsoft® Visual Basic® example creates an IXMLDOMNode
object from another node object's parent and displays its XML.
Dim xmlDoc As New Msxml2.DOMDocument50 Dim currNode As IXMLDOMNode Dim newNode As IXMLDOMNode xmlDoc.async = False xmlDoc.Load ("books.xml") If (xmlDoc.parseError.errorCode <> 0) Then Dim myErr Set myErr = xmlDoc.parseError MsgBox("You have error " & myErr.reason) Else Set currNode = xmlDoc.documentElement.childNodes.Item(1).childNodes.Item(0) Set newNode = currNode.parentNode MsgBox newNode.xml End If
C/C++ Syntax
HRESULT get_parentNode( IXMLDOMNode **parent);
Parameters
- parent [out, retval]
- The parent of the given node instance.
C/C++ Return Values
- S_FALSE
- The value returned if there is no parent.
- S_OK
- The value returned if successful.
- E_INVALIDARG
- The value returned if the
parent
parameter is Null.
Remarks
The property is read-only. All nodes except Document, DocumentFragment, and Attribute nodes can have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, the parent is Null.
This value depends on the value of the nodeType
property.
NODE_ATTRIBUTE
NODE_DOCUMENT NODE_DOCUMENT_FRAGMENT |
Returns Null; these nodes do not have parents. |
NODE_CDATA_SECTION | Returns the element or entity reference containing the CDATA section. |
NODE_COMMENT | Returns the element, entity reference, document type, or document containing the comment. |
NODE_DOCUMENT_TYPE | Returns the document node. |
NODE_ELEMENT | Returns the parent node of the element. If the element is the root node in the tree, the parent is the document node. If the node is the document node, parentNode is Null. |
NODE_ENTITY | Returns the document type node. |
NODE_ENTITY_REFERENCE | Returns the element, attribute, or entity reference containing the entity reference. |
NODE_NOTATION | Returns the document type node. |
NODE_PROCESSING_INSTRUCTION | Returns the document, element, document type, or entity reference containing the processing instruction. |
NODE_TEXT | Returns the parent element, attribute, or entity reference. |
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
See Also
Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText