XML DOM nodeType 属性
定義と用法
nodeType 属性はノードのタイプを返します。
文法:
attrObject.nodeType
例
すべての例で、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)