etc.
Tracy
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Mark Carter
Sent: Monday, September 22, 2008 11:45 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] e4x problem - filtering elements based on
multiple child
Ok, that subject is a bit vague but here's an example of what I mean:
group id=1
namefred/name
namebob/name
namepeter/name
/group
Say we have lots of these group elements in an XML document. I want to
select all groups including the names fred and bob, for example. Is it
possible in one e4x
try this:
rootXML.group.(name.text().contains(fred) name.text().contains(bob))
- Daniel Freiman
On Mon, Sep 22, 2008 at 5:20 AM, Mark Carter [EMAIL PROTECTED] wrote:
Ok, that subject is a bit vague but here's an example of what I mean:
group id=1
namefred/name
namebob/name
Oh cool, that works, thanks very much Daniel.
Am I right in thinking that name.text() is returning an XMLList of text
nodes and contains(fred) is basically looking for a match of fred in
that list?
In real life, instead of having two names, I have an array of names. I
suppose its not possible
You're correct, but you can also do the filtering in a loop to be dynamic:
var result:XMLList = rootXML.group.(name.text().contains(fred));
for each (filterName) { // psuedo-code
result = result.(name.text().contains(filterName));
}
return result;
- Daniel Freiman
On Mon, Sep 22, 2008 at
That doesnt work for me. Arent you trying to match fred against the
lowercased name.text() XMLList?
xitij2000 wrote:
i performed a similar operation by doing:
rootXML.group.(name.text().toLowerCase()==fredname.text().toLowerCase()==bob)
the toLowerCase is just because i needed case
I think you'd actually be matching fred against the first item in the
list, which would means that the entire expression would always return false
because the first item can't be both bob and fred.
On Mon, Sep 22, 2008 at 11:05 AM, Mark Carter [EMAIL PROTECTED] wrote:
That doesnt work for me.
Nice. I see what you've done there (instead of var result:XMLList =
rootXML.group.name; as the first line which would have been rather
inefficient).
I suppose this general approach doesnt work if I want to do things like
lowercase or substring matching...?
Daniel Freiman wrote:
You're
I get value is not a function - I guess because toLowerCase() cannot work
on an XMLList. You would have to do:
rootXML.group.(name.text()[0].toLowerCase()==fredname.text()[0].toLowerCase()==bob)
which, like you say, would always return nothing.
Or you have to specify group elements with
name.text()[0] will give you a single XML node of Kind string. If you want
to operate on it as a string simply do: name.text()[0].toString()
On Mon, Sep 22, 2008 at 11:35 AM, Mark Carter [EMAIL PROTECTED] wrote:
I get value is not a function - I guess because toLowerCase() cannot work
on an
It seems to work it out for you when it can.
name.text()[0].toLowerCase() works
name.text().toLowerCase() also works if there is exactly one name child of
each group element.
Daniel Freiman wrote:
name.text()[0] will give you a single XML node of Kind string. If you
want
to operate on it
(sItem.indexOf(sMatch) != -1);
}//contains
Tracy
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Mark Carter
Sent: Monday, September 22, 2008 11:59 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] e4x problem - filtering elements
Thanks - thats very useful - hadn't thought of that. Assumed it would not be
possible.
Whats the best way to get a handle on the item element from within the
itemContains function?
I would probably go with this approach:
xlFilteredItems =
_xmlData..group.(nameElementsContainAll(name,filters));
Oops - missed out a check on the match:
// assuming filters are lower case and distinct...
private function nameElementsContainAll(nameElements:XMLList,
filters:Array):Boolean {
var matchedFilters:Array = new Array();
for each (var nameElement:XML in nameElements) {
var
14 matches
Mail list logo