Easy Tutorial
❮ Dom Mozilla Vs Ie Prop Document Nodetype ❯

XML DOM getElementsByTagNameNS() Method



Definition and Usage

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

Syntax

Parameter Description
ns A string specifying the namespace URI to search for. The value "*" matches all tags.
name A string specifying the tag name to search for. The value "*" matches all tags.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and adds namespace-qualified element nodes to each <book> element:

Example

xmlDoc = loadXMLDoc("books.xml");

x = xmlDoc.getElementsByTagName('book');
var newel, newtext;

for (i = 0; i < x.length; i++) {
  newel = xmlDoc.createElementNS("p", "edition");
  newtext = xmlDoc.createTextNode("First");
  newel.appendChild(newtext);
  x[i].appendChild(newel);
}

// Output all titles and editions
y = xmlDoc.getElementsByTagName("title");
z = xmlDoc.getElementsByTagNameNS("p", "edition");
for (i = 0; i < y.length; i++) {
  document.write(y[i].childNodes[0].nodeValue);
  document.write(" - ");
  document.write(z[i].childNodes[0].nodeValue);
  document.write(" edition.");
  document.write(" Namespace: ");
  document.write(z[i].namespaceURI);
  document.write("<br>");
}

❮ Dom Mozilla Vs Ie Prop Document Nodetype ❯