User Guide
1028 Chapter 2: ActionScript Language Reference
XML.hasChildNodes()
Availability
Flash Player 5.
Usage
my_xml.hasChildNodes() : Boolean
Parameters
None.
Returns
A Boolean value.
Description
Method; returns true if the specified XML object has child nodes; otherwise, returns 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("<login><username>hank</username>
<password>rudolph</password></login>");
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