ホーム HTML CSS XML JAVASCRIPT   PHP SQL MORE...   リファレンス 事例集    

XML DOM getElementsByTagNameNS() メソッド


Document オブジェクト Reference Document オブジェクト

定義と用法

getElementsByTagNameNS() メソッドは、指定した名前と名前空間を持つ全要素の NodeList を返します。

構文

getElementsByTagNameNS(ns,name)

パラメータ 説明
ns検索する名前空間を指定する文字列。 値 "*" は全てのタグにマッチします
name検索するタグ名を指定する文字列。 値 "*" は全てのタグにマッチします


次のコードは、loadXMLDoc() を使用して xmlDoc に "books.xml" をロードし、 各 <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);
}

//Output all titles and editions
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("<br />");
}

Try it yourself »

Document オブジェクト Reference Document オブジェクト