Create an Element in XML
by satheesh[ Edit ] 2010-01-30 10:22:14
Create an Element
******************
The createElement() method creates a new element node.
The createTextNode() method creates a new text node.
The appendChild() method adds a child node to a node (after the last child).
To create a new element with text content, it is necessary to create both an element node and a text node.
The following code creates an element (<edition>), and adds it to the first <book> element:
Example
********
newel=xmlDoc.createElement("edition");
newtext=xmlDoc.createTextNode("First");
newel.appendChild(newtext);
x=xmlDoc.getElementsByTagName("book");
x[0].appendChild(newel);