View comments | RSS feed

nextSibling (XMLNode.nextSibling property)

public nextSibling : XMLNode [read-only]

An XMLNode value that references the next sibling in the parent node's child list. This property is null if the node does not have a next sibling node. This property cannot be used to manipulate child nodes; use the appendChild(), insertBefore(), and removeNode() methods to manipulate child nodes.

Availability: ActionScript 1.0; Flash Player 5

Example

The following example is an excerpt from the example for the XML.firstChild property, and shows how you can use the XML.nextSibling property to loop through an XML node's child nodes:

for (var aNode:XMLNode = rootNode.firstChild; aNode != null; aNode = aNode.nextSibling) {
    trace(aNode);
}

See also

firstChild (XMLNode.firstChild property), appendChild (XMLNode.appendChild method), insertBefore (XMLNode.insertBefore method), removeNode (XMLNode.removeNode method), XML


Flash CS3


Comments


oroboros777 said on Oct 19, 2007 at 1:45 PM :
If you need to recursively go through an XML file, when you don't know how many levels deep it goes, how many nodes it has, whether it has attributes or values, etc., try this:

function GoThroughXML(xHolder:XMLNode):Void
{
if (xHolder.hasChildNodes())
{
var xN:Number = 0;
for (var xNode:XMLNode=xHolder.firstChild; xNode != null; xNode=xNode.nextSibling)
{
if (xNode.nodeType == 1)
{
trace("Node["+xN+"]: "+xNode.nodeName);
var oAttr:Object = xNode.attributes;
for (var sAttr:String in oAttr)
{
trace(" Atrbs: "+sAttr+"="+oAttr[sAttr]);
}
}
else if (xNode.nodeType == 3)
{
trace(" Value: "+xNode.nodeValue);
}
xN = xN+1;
GoThroughXML(xNode);
}
}
}

var xData:XML = new XML();
xData.ignoreWhite = true;
xData.load("xml_data.xml");

xData.onLoad = function(YoN:Boolean):Void
{
if(YoN)
{
//trace(this.toString());
if (xData.status == 0)
{

var xChecker:XMLNode = xData;
//trace("xC: "+xChecker);
while (xChecker != null)
{
GoThroughXML(xChecker);
xChecker = xChecker.nextSibling;
}

}
else
{
trace("XML Status Error: " + xData.status);
}
}
else
{
trace("XML Loading Error");
}
}

Note that I did not put an 'onHTTPStatus' check in this example, which should also be done.

 

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/00002357.html