XML DOM nodeValue 属性
最后更新于:2022-03-26 22:39:26
XML DOM nodeValue 属性
定义和用法
nodeValue 属性设置或返回节点的值,根据其类型。
语法
attrObject.nodeValue
实例
下面的代码片段使用 loadXMLDoc() 把 “books.xml” 载入 xmlDoc 中,并显示 category 属性的节点名称、节点值和节点类型:
实例
xmlDoc=loadXMLDoc("books.xml");
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: " + x.item(i).attributes[0].nodeType + ")");
document.write("<br>");
}
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: " + x.item(i).attributes[0].nodeType + ")");
document.write("<br>");
}
输出:
category = COOKING (nodetype: 2)
category = CHILDREN (nodetype: 2)
category = WEB (nodetype: 2)
category = WEB (nodetype: 2)
category = CHILDREN (nodetype: 2)
category = WEB (nodetype: 2)
category = WEB (nodetype: 2)