PDA

View Full Version : XML node length (easy for the pro..)



Theofiel
January 28th, 2009, 08:11 PM
Hi All,

I try to get the node length from my XML file, I followed the Senocular tut on XML and AS3, very helpfull, but still I 'm stuck and any search on google or forum is a confusing mix from AS2, so please some help.

When I trace xmlData, it works fine. I found several notations for node length, I came up with this...:hangover:

code:
import fl.transitions.Tween;
import fl.transitions.easing.*;

var nodes:Number;
var aantal:Number;

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlData.ignoreWhite=true;

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("sampleXML.xml"));

function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
nodes = xmlData.firstChild.length;
aantal = nodes.length;
trace (aantal);
}


XML file:

<snippers>
<snipper image="snipper1.png" snippertekst="Zwemmen" />
<snipper image="snipper2.png" snippertekst="Fietsen" />
<snipper image="snipper3.png" snippertekst="Lopen" />
<snipper image="snipper4.png" snippertekst="Training" />
<snipper image="snipper5.png" snippertekst="Wissel"/>
<snipper image="snipper6.png" snippertekst="Materiaal" />
<snipper image="snipper7.png" snippertekst="Techniek" />
<snipper image="snipper8.png" snippertekst="Begeleiding" />
<snipper image="snipper9.png" snippertekst="Trainer" />
<snipper image="snipper10.png" snippertekst="Voeding" />
</snippers>

senocular
January 28th, 2009, 09:28 PM
xmlData.elements().length() will give you a count of all the element nodes in your xml if that's what you're looking for.

Theofiel
January 29th, 2009, 04:33 AM
xmlData.elements().length() will give you a count of all the element nodes in your xml if that's what you're looking for.

And again saves sen MY day...:pleased:

What would this forum be without him..

Tankx