And also, here's a full example of what I mean- with E4X syntax, you can
take advantage of XMLLists within your XML:
var xml:XML = <xml>
<node>
<node firstName="WALDO" lastName="Williams"/>
<node firstName="Bill" lastName="Smith"/>
<node firstName="Susan" lastName="Jones"/>
</node>
<node firstName="WALDO" lastName="Peterson">
<node>
<node firstName="Larry" lastName="Anderson"/>
<node firstName="Mary" lastName="Williams"/>
<node firstName="Mary" lastName="WALDO"/>
<node firstName="WALDO" lastName="Williams"/>
</node>
</node>
<node>
<node>
<node firstName="Larry" lastName="WALDO"/>
<node firstName="WALDO" lastName="WALDO"/>
<node firstName="Larry" lastName="WALDO"/>
<node firstName="WALDO" lastName="Perkins"/>
<node firstName="Jenny" lastName="WALDO">
<node firstName="Hank" lastName="Smith"
/>
<node firstName="WALDO" lastName="Smith"
/>
</node>
</node>
</node>
</xml>
trace("How many firstName WALDOs?
"+xml..*.(attribute("firstName")=="WALDO").length());
trace("How many lastName WALDOs?
"+xml..*.(attribute("lastName")=="WALDO").length());
trace("------------")
trace("Here are all the nodes (with their subnodes) that have WALDO as
the value for firstName or lastName:
\r\r"+xml..*.(attribute("firstName")=="WALDO" ||
attribute("lastName")=="WALDO"));
//traces:
How many firstName WALDOs? 6
How many lastName WALDOs? 5
------------
Here are all the nodes (with their subnodes) that have WALDO as the
value for firstName or lastName:
<node firstName="WALDO" lastName="Williams"/>
<node firstName="WALDO" lastName="Peterson">
<node>
<node firstName="Larry" lastName="Anderson"/>
<node firstName="Mary" lastName="Williams"/>
<node firstName="Mary" lastName="WALDO"/>
<node firstName="WALDO" lastName="Williams"/>
</node>
</node>
<node firstName="Mary" lastName="WALDO"/>
<node firstName="WALDO" lastName="Williams"/>
<node firstName="Larry" lastName="WALDO"/>
<node firstName="WALDO" lastName="WALDO"/>
<node firstName="Larry" lastName="WALDO"/>
<node firstName="WALDO" lastName="Perkins"/>
<node firstName="Jenny" lastName="WALDO">
<node firstName="Hank" lastName="Smith"/>
<node firstName="WALDO" lastName="Smith"/>
</node>
<node firstName="WALDO" lastName="Smith"/>
Jason Merrill
Bank of America Global Learning
Learning & Performance Solutions
Join the Bank of America Flash Platform Community and visit our
Instructional Technology Design Blog
(note: these are for Bank of America employees only)
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Merrill,
Jason
Sent: Friday, March 26, 2010 12:14 PM
To: Flash Coders List
Subject: RE: [Flashcoders] Counting xml attributes
Actually, another option, you already have that information with E4X
syntax, so this could nerdily be handled in a single line. So for
example, if you wanted to see how many nodes had an firstName attribute
with the value of "Hank" ( <mynode firstName="Hank" />) then you can do
this:
xml..*.(attribute("firstName")=="Hank").length();
Jason Merrill
Bank of America Global Learning
Learning & Performance Solutions
Join the Bank of America Flash Platform Community and visit our
Instructional Technology Design Blog
(note: these are for Bank of America employees only)
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
Geografiek
Sent: Friday, March 26, 2010 5:09 AM
To: Flash Coders List
Subject: Re: [Flashcoders] Counting xml attributes
Hi Theodore,
Something like (code not tested):
var counter:uint = 0;
for each (node in myXml..*) {
if(no...@myatt == givenValue) {
counter++;
}
}
trace(counter);
HTH
Willem van den Goorbergh
On 23-mrt-2010, at 14:20, Lehr, Theodore wrote:
> Is there a way to loop through xml and count how many times an
> attribute has a given value?
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Geografiek is a Dutch, Utrecht-based map and chart design company.
Willem van den Goorbergh can be contacted by telephone: (+31)
30-2719512 or cell phone: (+31)6-26372378
or by fax: (+31)302719687
snail mail: Hooghiemstraplein 89 3514 AX UTRECHT
Visit our website at: http://www.geografiek.nl
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders