XML DOM getAttributeNode() 方法

Element 对象参考手册

定义和用法

getAttributeNode() 方法从当前元素中通过名称获取属性节点。

语法:

elementNode.getAttributeNS(ns,name)
参数 描述
name 必需。规定要获取的属性节点。
本在线速查手册由www.w`3`x`u`e.com提供,请勿盗用!

说明

该方法将返回一个 Attr 节点,表示指定的属性和值。请注意,通过从 Node 接口继承的 attributes 属性也可以获取该属性节点。

实例

在所有的例子中,我们将使用 XML 文件 books.xml,以及 JavaScript 函数 loadXMLDoc()

下面的例子从 "books.xml" 中的所有 <book> 元素获取 "category" 属性:

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName('book');

for(i=0;i<x.length;i++)
{
attnode=x.item(i).getAttributeNode("category");
document.write(attnode.name);
document.write(" = ");
document.write(attnode.value);
document.write("<br />");
}

以上代码的输出:

category = COOKING
category = CHILDREN
category = WEB
category = WEB

TIY

getAttributeNode() - 获取拥有特定名称的所有属性节点

Element 对象参考手册