XML DOM getAttributeNS() Method
Definition and Usage
The getAttributeNS() method retrieves the attribute value by namespace URI and name.
Syntax:
elementNode.getAttributeNS(ns,name)
Parameters | Description |
---|---|
ns | Required. Specifies the namespace URI to obtain the attribute value from. |
name | Required. Specifies the attribute to obtain the attribute value from. |
Example
In all examples, we will use the XML file books_ns.xml, and the JavaScript function loadXMLDoc().
The following code snippet retrieves the value of the "lang" attribute from the first <title> element in "books_ns.xml":
xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName("title")[0];
ns="http://www.codew3c.com/children/";
document.write(x.getAttributeNS(ns,"lang")
;
The output of the above code is:
en