XML DOM getElementsByTagNameNS() 方法

定义和用法

getElementsByTagNameNS() 方法返回带有指定名称和命名空间的所有元素的 NodeList。

语法:

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 functions 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:

c:title