nodeType Property
Last Updated: 08-19-2005
Retrieves the type of the node.

Syntax
var iType = object.nodeType;

Possible Values
iType One of the following values:
NODE_ATTRIBUTE (2) DEPRECATED. Use Node.ATTRIBUTE_NODE instead.
NODE_CDATA_SECTION (4) DEPRECATED. Use Node.CDATA_SECTION_NODE instead..
NODE_DOCUMENT (9) DEPRECATED. Use Node.DOCUMENT_NODE instead..
NODE_ELEMENT (1) DEPRECATED. Use Node.ELEMENT_NODE instead.
NODE_TEXT (3) DEPRECATED. Use Node.TEXT_NODE instead.
Node.ATTRIBUTE_NODE (2) Returned by an attribute node. Attribute nodes are returned by iterating through the attributes collection.
Node.CDATA_SECTION_NODE (4) Returned by a CDATA section.
Node.COMMENT_NODE (8) Returned by a comment node.
Node.DOCUMENT_NODE (9) Returned by the document object.
Node.ELEMENT_NODE (1) Returned by an element node.
Node.PROCESSING_INSTRUCTION_NODE (7) Returned by a processing instruction.
Node.TEXT_NODE (3) Returned by a text node.

Remarks
Prior to revision 3, the Tellme platform treats CDATA section nodes as text nodes. In revision 3 and later, they are treated independently.
Examples

The example below utilizes the following sample data describing a contact.

<?xml version="1.0"?>
<?access-control allow="*"?>
<contact>
   <name><![CDATA[Amos & Andy]]></name>
   <address>
   <line>915 Commonwealth Avenue</line>
   <line>Apartment 506</line>
   <city>Boston</city>
   <state>Massachusetts</state>
   <zip>02215</zip>
</address>
</contact>

The following example reads back contact info by iterating through the nodes of an XML document and looking for text nodes and CDATA sections by checking the nodeType property of each node encountered. The text is collected into an array and read back to the user.

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

   <data name="oContact" src="contact.xml"/>
   <script>
   function GetContactInfo(oData)
   {
      var aInfo = [];
      var oRoot = oData.documentElement;
      GetTextNodes(oRoot, aInfo);
      return aInfo;
   }

   function GetTextNodes(oNode, aText)
   {
      for (var i = 0; i &lt; oNode.childNodes.length; i++)
      {
         var oChild = oNode.childNodes.item(i);
         switch(oChild.nodeType)
         {
            case Node.ELEMENT_NODE:
               GetTextNodes(oChild, aText);
               break;
            case Node.TEXT_NODE:
            case Node.CDATA_SECTION_NODE:
               aText.push(oChild.data);
               break;
            otherwise:
               Log("Unsupported node type: " + oChild.nodeType);
               continue;         
         }
      }
   }
   </script>
   <form id="main">
   <block>
      <foreach item="sNugget" array="GetContactInfo(oContact)">
         <audio><value expr="sNugget"/></audio>
      </foreach>
   </block>
   </form>
</vxml>



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