Appends a new child node as the last child of the node.
var objXMLDOMNode = oXMLDOMNode.appendChild(newChild);
An object. Returns the new child node successfully appended to the list.
The following script example creates a new IXMLDOMNode
object, and then uses the appendChild
method to append it to the document's list of children.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); var root; 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 { root = xmlDoc.documentElement; alert(root.xml); newNode = xmlDoc.createNode(1, "VIDEOS", ""); root.appendChild(newNode); alert(root.xml); }
This is equivalent to calling insertBefore(newChild, null)
. For more information, see insertBefore Method.
Set objXMLDOMNode = oXMLDOMNode.appendChild(newChild)
An object. Returns the new child node successfully appended to the list.
The following Microsoft® Visual Basic® example creates a new IXMLDOMNode
object, and then uses the appendChild
method to append it to the document's list of children.
Dim xmlDoc As New Msxml2.DOMDocument50 Dim root As IXMLDOMElement 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 root = xmlDoc.documentElement MsgBox root.xml Set newNode = xmlDoc.createNode(NODE_ELEMENT, "VIDEOS", "") root.appendChild newNode MsgBox root.xml End If
This is equivalent to calling insertBefore(newChild, null)
. For more information, see insertBefore Method.
HRESULT appendChild( IXMLDOMNode *newChild, IXMLDOMNode **outNewChild);
newChild
parameter is Null.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.
If the newChild
parameter has an existing parent, the node is automatically removed from that parent before being inserted into its new location.
A node retains its namespace information even when moved. Moving a node does not create a namespace declaration; declarations are added when retrieving the XML source (through the save
method or the xml
property) to ensure that all namespaces are properly declared.
When inserting a node tree under another node that has a different owner document, the ownerDocument
property for each inserted node is changed to match the owner document of its new parent.
When moving a node tree to another document, the content of all entity reference nodes contained therein is updated to conform to the new document. If the new document does not declare an entity that was moved into it, the entity reference will have no children, and the old content is removed. Existing references to nodes under the entity reference are still valid, but the node whose parent previously was the entity reference now has a null parent.
save Method | xml Property | ownerDocument Property
Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText