View comments | RSS feed

hasChildNodes (XMLNode.hasChildNodes method)

public hasChildNodes() : Boolean

Specifies whether or not the XML object has child nodes.

Availability: ActionScript 1.0; Flash Player 5

Returns

Boolean - true if the specified XMLNode has one or more child nodes; otherwise false.

Example

The following example creates a new XML packet. If the root node has child nodes, the code loops over each child node to display the name and value of the node. Add the following ActionScript to your FLA or AS file:

var my_xml:XML = new XML("hankrudolph");
if (my_xml.firstChild.hasChildNodes()) {
// use firstChild to iterate through the child nodes of rootNode
    for (var aNode:XMLNode = my_xml.firstChild.firstChild; aNode != null; aNode=aNode.nextSibling) {
        if (aNode.nodeType == 1) {
            trace(aNode.nodeName+":\t"+aNode.firstChild.nodeValue);
        }
    }
}

The following is displayed in the Output panel:

 output:
 username: hank
 password: rudolph 


Flash CS3


Comments


gaw.in said on Sep 11, 2007 at 9:08 PM :
The example code will not generate the suggested output in the Output
panel.
This is the correct code:

var my_xml:XML = new XML("<user><username>hank</
username><password>rudolph</password></user>");
trace("output:");
if (my_xml.firstChild.hasChildNodes()) {
// use firstChild to iterate through the child nodes of rootNode
for (var aNode:XMLNode = my_xml.firstChild.firstChild; aNode != null;
aNode=aNode.nextSibling) {
if (aNode.nodeType == 1) {
trace(aNode.nodeName+":\t"+aNode.firstChild.nodeValue);
}
}
}

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00002352.html