Name
XML.createElement( ) Method — create a new element node
Availability
Flash 5
Synopsis
XMLdoc.createElement(tagName)
Arguments
- tagName
A case-sensitive string indicating the name of the element to create. For example, in the tag,
<P ALIGN="RIGHT">,Pis the tag name.
Returns
A new element node object, with no parent and no children.
Description
The createElement( ) method is our primary means
of generating new element nodes for inclusion in an
XML
document object hierarchy. Note that
createElement( ) 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:
myDoc = new XML( );
newP = myDoc.createElement("P");
myDoc.appendChild(newP);We can combine those steps like this:
myDoc.appendChild(myDoc.createElement("P"));
XMLdoc must be an instance of the
XML class, not the XMLnode
class.
The createElement( ) method cannot be used to
create text nodes; use createTextNode( )
instead.
See Also
XML.appendChild( ), XML.cloneNode(
), XML.createTextNode( ),
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