XML DOM nodeName 属性
定义和用法
nodeName 属性根据节点的类型返回其名称。
语法:
attrObject.nodeName
实例
在所有的例子中,我们将使用 XML 文件 books.xml,以及 JavaScript 函数 loadXMLDoc()。
下面的代码片段显示 category 属性的节点名称、节点值以及节点类型:
xmlDoc=loadXMLDoc("/static/demo/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)