XML DOM nodeName 属性

定義と用法

nodeName 属性はノードのタイプに応じてその名前を返します。

文法:

attrObject.nodeName

インスタンス

すべての例において、XML ファイルを使用します books.xml、および JavaScript ファンクション loadXMLDoc()

以下のコードスニペットは、category 属性のノード名、ノード値、およびノードタイプを表示しています:

xmlDoc=loadXMLDoc("/example/xdom/books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write(x.item(i).attributes[0].nodeName);
document.write(" = ");
document.write(x.item(i).attributes[0].nodeValue);
document.write(" (nodetype: ");
document.write(x.item(i).attributes[0].nodeType + ")");
document.write("<br />");
}

以下のコードの結果:

category = children (nodetype: 2)
category = cooking (nodetype: 2)
category = web (nodetype: 2)
category = web (nodetype: 2)