Create an Element in XML

by satheesh 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);

Tagged in:

872
like
0
dislike
0
mail
flag

You must LOGIN to add comments