XML DOM getElementsByTagNameNS()メソッド
Document オブジェクト
定義と用法
getElementsByTagNameNS() メソッドは、指定された名前と名前空間を持つすべての要素の NodeList を返します。
構文
getElementsByTagNameNS(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 オブジェクト その他の拡張