getElementsByTagNameNS Method
Last Updated: 08-26-2005
Returns a NodeList collection of descendant element nodes with the specified local name and namespace URI.

Syntax
var oNodeList = object.getElementsByTagNameNS(sNamespaceURI, sLocalName);

Parameters
sNamespaceURI Required. The namespace URI of the elements to match on. The special value "*" matches all namespaces.
sLocalName Required. The local name of the elements to match on. The special value "*" matches all local names.

Return Value
The list of element nodes with the specified local name and namespace URI.

Remarks
The getElementsByTagNameNS method searches recursively through all descendant nodes of the current node searching for node elements with the specified namespace URI and local name.
If there are no nodes with the specified local name and namespace URI that are descendants of the current node, the getElementsByTagNameNS method returns a NodeList of length zero.
Examples

The example below utilizes the following sample data ...

<?xml version="1.0"?>
<?access-control allow="*"?>

<dis:pkgs xmlns:dis="http://disney.com" 
xmlns:aa="http://aa.com" xmlns:av="http://avis.com"  
xmlns:hz="http://hertz.com" xmlns:sw="http://southwest.com" 
xmlns:us="www.universalstudios.com">
  <dis:pkg>
    <dis:stay>3</dis:stay>
    <dis:tix>1</dis:tix>
    <us:tix>1</us:tix>
    <aa:from>SJC</aa:from> 
    <dis:price>328</dis:price>
  </dis:pkg>

  <dis:pkg>
    <dis:stay>4</dis:stay>
    <dis:tix>2</dis:tix>
    <aa:from>SEA</aa:from>
    <dis:price>499</dis:price>
  </dis:pkg>

  <dis:pkg>
    <dis:stay>4</dis:stay>
    <dis:tix>3</dis:tix>
    <sw:from>SEA</sw:from>
    <dis:price>539</dis:price>
  </dis:pkg>

</dis:pkgs>

Here is a program that calls getElementsByTagNameNS to determine the number of Disneyland packages that utilize American Airlines. It outputs to the debug log information about each node found: the localName, the prefix, and the node's firstChild.data, which tells the airport code.

<vxml version="2.1"
  xmlns="http://www.w3.org/2001/vxml">

  <data name="dom" src="vacationpkgs.xml"/>
  
  <script><![CDATA[
      var root = dom.documentElement;
      var oNodeList = 
        root.getElementsByTagNameNS('http://aa.com', 'from');
      var nodeCount = oNodeList.length;
      vxmllog(
        "There are " + nodeCount + " nodes returned by " +
        "getElementsByTagNameNS('http://aa.com', 'from'), and thus " +
        nodeCount + " packages that utilize American Airlines.")
      vxmllog(
        "The nodes returned by getElementsByTagNameNS are:")
      for (var i = 0; i < nodeCount; i++) {
        var node = oNodeList.item(i);
        vxmllog(
          "number " + (i+1) + ": prefix: " + node.prefix +
          ", local name: " + node.localName +
          ", data (airport): " + node.firstChild.data)
      }            
  ]]></script>
</vxml>


Applies To
element, document
[24]7 Inc.| Terms of Service| Privacy Policy| General Disclaimers