Name
XML.createTextNode( ) Method — create a new text node
Availability
Flash 5
Synopsis
XMLdoc.createTextNode(text)
Arguments
- text
A string containing the text that is to become the
nodeValueof the new node.
Returns
A new text node object, with no parent and no children.
Description
The createTextNode( ) method is our primary
means of generating new text nodes for inclusion in an
XML document object hierarchy. Note that
createTextNode( ) does not insert the element it
returns into XMLdoc—we must do that
ourselves using appendChild( ) or
insertBefore( ). For example, here we create and
insert a new P element into a document, and then
we give that P element a text-node child:
myDoc = new XML( );
newP = myDoc.createElement("P");
myDoc.appendChild(newP);
newText = myDoc.createTextNode("This is the first paragraph");
myDoc.firstChild.appendChild(newText);
trace(myDoc); // Displays: "<P>This is the first paragraph</P>"
XMLdoc must be an instance of the
XML class, not the XMLnode
class.
Text nodes are normally stored as the children of element nodes,
which are created using createElement( ).
See Also
XML.appendChild( ), XML.cloneNode(
), XML.createElement( ),
XML.insertBefore( )
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access