XML DOM getElementsByTagNameNS() Method

Definition and Usage

getElementsByTagNameNS() The method returns a NodeList containing all elements with the specified name and namespace.

Syntax

elementNode.getElementsByTagNameNS(ns,name)
Parameter Description
ns A string that specifies the namespace to search for. The value "*" matches all tags.
name A string that specifies the tag name to search for. The value "*" matches all tags.

Example

The following code loads "books_ns.xml" into xmlDoc and retrieves elements by tag name and namespace:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   {}
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagNameNS("https://www.codew3c.com/meishi/", "title");
    document.getElementById("demo").innerHTML =
    x[0].nodeName;
{}

Try It Yourself