XML DOM getElementsByTagNameNS() Method
Definition and Usage
The getElementsByTagNameNS() method returns a NodeList of all elements with the specified name and namespace.
Syntax:
elementNode.getElementsByTagNameNS(ns,name)
Parameters | Description |
---|---|
ns | String value, specifies the namespace to be searched for. The value "*" matches all tags. |
name | String value, specifies the tag name to be searched for. The value "*" matches all tags. |
Description
This method is similar to getElementsByTagName() MethodSimilar, but the tag name to be retrieved is specified as a combination of namespace URI and the local name defined in the namespace. This method is only used for XML documents that use namespaces.
Example
In all examples, we will use XML files books_ns.xml, and JavaScript function loadXMLDoc().
The following code snippet retrieves elements by tag name and namespace:
xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagNameNS("http://www.codew3c.com/children/","title")
;
document.write(x[0].nodeName);
The output of the above code is:
c:title