METHOD:  Document::createTextNode


The createTextNode method creates a new Text object whose value is the data passed as the parameter. This object, however, is not automatically included in the document tree but must be specifically inserted into it using one of the insertion methods: insertBefore, replaceChild or appendChild. Its parentNode property is therefore set to null.

To demonstrate this method, the following example uses the 'names.xml' file and creates a new 'name' element and a new text node with the value of 'Felix' 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 first child of the root's last child (the text of the newly-appended 'name' element), and its type, name and value are displayed.


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

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

Set objCurrNode = objXMLDoc.documentElement
Set objCurrNode = objCurrNode.lastChild.firstChild
document.write("<br>" & objCurrNode.nodeName)
document.write("<br>" & objCurrNode.nodeValue)


The value '3' returned for the node's type indicates that it is a Text object (see the list of node types).

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