childNodes Property
Last Updated: 08-27-2005
Retrieves a NodeList collection of node objects.

var oNodes = Node.childNodes;

Possible Values
oNodes A NodeList collection of node objects.

If a node doesn't contain any children, the length property of the childNodes property returns the value 0. The hasChildNodes method returns false.
Before calling the item method on the object returned by the childNodes property of a node object, check the value of the length property to ensure that it is greater than zero, or call the node's hasChildNodes method and check for the value true.

The example below utilizes the following sample data describing a stock quote.

<?xml version="1.0"?>
<?access-control allow="*"?>
   <name>Ford Motor Company</name>

The following example reads back information about a stockquote to the user. The Node2Array function uses the childNodes property of the root document element to retrieve a NodeList (oChildren) containing the children of that element. The length of the list is determined from the length property, The code iterates through the NodeList, calling the item method to obtain each child in turn and push its data onto an array.

<vxml version="2.0">
<data name="oQuote" src="quote.exml"/>

<catch event="error.badfetch">
   <log>Caught error.badfetch. Must have faulted loading data.</log>


// hash table w/strings describing each node in the quote data
var hQuotePrompts = {
   "name" : "The company name is ",
   "ticker" : "The company ticker symbol is ",
   "open" : "The stock opened today at ",
   "last" : "The current price per share is ",
   "change" : "The change in value is ",
   "day_high" : "The day's high is ",
   "day_low" : "The day's low is "

// convert the DOM node to an array of objects. 
// Since we know the data, this code assumes the node contains 
// elements that contain children that are text nodes
function Node2Array(oNode)
  var a = []; // array to hold data

  // cache the collection of children
  var oChildren = oNode.childNodes;
  var iChildren = oChildren.length;

  // do we have any children to iterate through?
  if (0 == iChildren)
     Log("no children encountered.");
     return a;

  // iterate through the children of the root element;
  for (var i = 0; i < iChildren; i++)
     // store the name of the node and the value of the text node contained within the node
     var oChild = oChildren.item(i);
     a.push({"name" : oChild.nodeName, "value" :});

  return a;

function Log(s) { vxmllog(s); }

<form id="read_quote_data">
   <if cond="oQuote != null">
         var aValues = Node2Array(oQuote.documentElement);
      <foreach item="oValue" array="aValues">
         <audio><value expr="hQuotePrompts[]"/> <value expr="oValue.value"/></audio>
      <log>Unable to load quote data. <value expr="typeof(oQuote)"/></log>

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