XML DOM createElementNS() Method
Complete Document Object Reference
Definition and Usage
The createElementNS() method creates an element node with a namespace.
This method returns an Element object.
Syntax
Parameter |
Description |
ns |
A string that specifies the namespace name for the element node |
name |
A string that specifies the name for the element node |
Example
The following code fragment loads "books.xml"
into xmlDoc using
loadXMLDoc() and adds an element node with a namespace to each <book> element:
mlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
var newel,newtext;
for (i=0;i<x.length;i++)
{
newel=xmlDoc.createElementNS('p','edition');
newtext=xmlDoc.createTextNode('First');
newel.appendChild(newtext);
x[i].appendChild(newel);
}
|
Try-It-Yourself Demos
createElementNS() - Create an element node with a namespace
Complete Document Object Reference
Learn XML with <oXygen/> XML Editor - Free Trial!
|
|
oXygen helps you learn to define,
edit, validate and transform XML documents. Supported technologies include XML Schema,
DTD, Relax NG, XSLT, XPath, XQuery, CSS.
Understand in no time how XSLT and XQuery work by using the intuitive oXygen debugger!
Do you have any XML related questions? Get free answers from the oXygen
XML forum
and from the video
demonstrations.
Download a FREE 30-day trial today!
|
|