XML DOM getAttributeNS() 方法

定义和用法

getAttributeNS() 方法通过命名空间 URI 和名称来获取属性值。

语法:

elementNode.getAttributeNS(ns,name)
参数 描述
ns 必需。规定从中获取属性值的命名空间 URI。
name 必需。规定从中取得属性值的属性。

实例

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

下面的代码片段从 "books_ns.xml" 中的第一个 <title> 元素中获取 "lang" 属性的值:

xmlDoc=loadXMLDoc("books_ns.xml");

x=xmlDoc.getElementsByTagName("title")[0];
ns="http://www.3wschool.com.cn/children/";

document.write(x.getAttributeNS(ns,"lang"));

以上代码的输出:

en