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