nodeName Property
Last Updated: 08-25-2005
Retrieves the name of the node.

Syntax
var sName = node.nodeName;

Possible Values
sName The name of the node.

Remarks
You can retrieve the set of nodes in an XML document with a specific name by using the getElementsByTagName method.
Prior to revision 3, comment and processing instruction nodes in an XML document are ignored, and CDATA section nodes are treated the same as text nodes. Various types of nodes are all recognized and treated independently in revision 3 and later, and, for compliance with the Interface Node section of the DOM 2 specification, there are some differences in nodeName values for various types of nodes. The following table shows the differences between the old (pre-revision 3) and new (revision 3) nodeName values.
Node Type Old nodeName New nodeName
Attribute attribute name attribute name
CDATASection "noname" "#cdata-section"
Comment N/A "#comment"
Document "_doc" "#document"
Element tag name tag name
ProcessingInstruction N/A target property
TextNode "noname" "#text"

Examples

The example below utilizes the following sample data describing a stock quote. In this sample data, "quote" is the name of the root document element.

<quote>
   <name>Ford Motor Company</name>
   <ticker>F</ticker>
   <open>28.35</open>
   <last>28.72</last>
   <change>.54</change>
   <day_high>29.03</day_high>
   <day_low>28.03</day_low>
</quote>

The following example uses the nodeName property to determine if the data contains the expected root element. If so, it reads back the company name and the latest price per share.

<vxml version="2.0">
   <data name="oQuote" src="quote.xml"/>
   <script>
      // compare the root element's name to an expected value
      function IsExpectedRoot(oData, sExpected)
      {
         var oRoot = oData.documentElement;
         return (sExpected == oRoot.nodeName ? true : false);
      }

      // return the company name from the quote data
      function GetCoName(oData)
      {
        var oRoot = oData.documentElement;
        return
          oRoot.getElementsByTagName("name").item(0).firstChild.data;
      }

      // return the price/share from the quote data
      function GetLast(oData)
      {
        var oRoot = oData.documentElement;
        return
          oRoot.getElementsByTagName("name").item(0).firstChild.data;
      }
   </script>
   <form id="main">
   <block>
      <if cond="oQuote &amp;&amp; IsExpectedRoot(oQuote, 'quote')">
         <audio><value expr="GetCoName(oQuote)"/> is currently at 
           <value expr="GetLast(oQuote)"/></audio>
      <else/>
         <audio>I'm sorry. I was unable to obtain your quote.</audio>
      </if>
   </block>
   </form>
</vxml>


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