METHOD:  Document::createElement

Document.createElement(tagName)

The createElement method is used to create an element and returns a new Element of the type specified by the tagName argument.

To demonstrate this, the following example first loads the 'names.xml' file. It then creates a new 'name' element and a text node with the value of 'John' which is appended to it. The new 'name' element is then appended to the document's root element, and finally the variable objCurrNode is set to the root's last child (the newly-appended 'name' element), and the value of its first child (the text node) is displayed.

XML:
<names>
   <name>Alice</name>
   <name>Bert</name>
   <name>Charlie</name>
   <name>Diane</name>
   <name>Eric</name>
</names>

Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("names.xml")

Dim objCurrNode, objNewNode, objNewText
Set objNewNode = objXMLDoc.createElement("name")
Set objNewText = objXMLDoc.createTextNode("John")
objNewNode.appendChild(objNewText)

Set objCurrNode = objXMLDoc.documentElement
objCurrNode.appendChild(objNewNode)
Set objCurrNode = objCurrNode.lastChild
document.write(objCurrNode.firstChild.nodeValue)

Output:
John



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information