XML DOM createElementNS()メソッド


Document 对象参考手册Document オブジェクト

定義と使用法

createElementNS() メソッドは名前空間を持つ要素ノードを作成します。

このメソッドは Element オブジェクトを返します。

構文

createElementNS(ns,name)

引数 説明
ns 文字列。要素ノードの名前空間の名前を指定できます。
name 文字列。要素ノードの名前を指定できます。


例

次のコード断片では、loadXMLDoc()"" を xmlDoc に読み込み、名前空間を持つ要素ノードを各 <book> 要素に追加します:

例

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); } //すべての title と edition を出力する y=xmlDoc.getElementsByTagName("title"); z=xmlDoc.getElementsByTagNameNS("p","edition"); for (i=0;i<y.length;i++) { document.write(y[i].childNodes[0].nodeValue); document.write(" - "); document.write(z[i].childNodes[0].nodeValue); document.write(" edition."); document.write(" Namespace: "); document.write(z[i].namespaceURI); document.write("<br>"); }

試してみる »

Document 对象参考手册Document オブジェクト その他の拡張