XML DOM createElementNS () method
Definition and Usage
createElementNS () method creates an element node with a namespace.
This method returns a Element object.
grammar
createElementNS(ns,name)
参数 | 描述 |
---|---|
ns | 字符串,可为元素节点规定命名空间的名称。 |
name | 字符串,可为元素节点规定名称。 |
Examples
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and add an element node with a namespace to each <book> element:
Examples
xmlDoc=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);
}
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"
Document Object