RE: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-23 Thread Tracy Spratt
I don't remember the all syntax offhand, but you can pass any XML
expression you want into the function.  For example, * would be an
xmllist of all children.  I think . would pass in the current
context node (I think that would be the item node in this case).
parent() would pass the parent node 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 conditions

 


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));

// 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 matchIndex:int =
filters.indexOf(nameElement.toString().toLowerCase());
var matchedFilter:String = filters[matchIndex];
if (matchedFilters.indexOf(matchedFilter)  0) { // in case name
appears multiple times in the group
matchedFilters.push(matchedFilter);
}
}
return matchedFilters.length() == filters.length();
}

Tracy Spratt wrote:
 
 This is not a direct answer to your immediate question , but rather a
 general tip:
 
 If you need complex calculations within an e4x expression, you can
call
 out to a function of your own. The () just requires a boolean value,
so
 you can do something like below, where I wanted to a bit of string
 manipulation within the expression:
 
 xlFilteredItems =
 _xmlData..item.(itemContains(attribute(item),sFilterString))
 
 
 
 and the function:
 
 private function itemContains(sItem:String, sMatch:String):Boolean
 
 {
 
 sItem = sItem.toLowerCase();
 
 sMatch = sMatch.toLowerCase();
 
 return (sItem.indexOf(sMatch) != -1);
 
 }//contains
 
 
 
 Tracy
 

-- 
View this message in context:
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple
-child-conditions-tp19604364p19620894.html
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multipl
e-child-conditions-tp19604364p19620894.html 
Sent from the FlexCoders mailing list archive at Nabble.com.

 



[flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Mark Carter

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 expression?

My guess would be: rootXML.group.name.(text() ==
fred).parent().name.(text() == bob).parent()

but the parent() part seems to be wrong.

Any ideas???

On a slightly different note...

I notice that rootXML.group.(name == fred) will only work for a group
containing fred and nothing else. Using rootXML.group.name.(text() ==
fred) sort of gives me what I want, but I really want the parent()
elements. Of course, I could iterate over the results but I really want to
do this in one expression.
-- 
View this message in context: 
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19604364.html
Sent from the FlexCoders mailing list archive at Nabble.com.



Re: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Daniel Freiman
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
 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 expression?

 My guess would be: rootXML.group.name.(text() ==
 fred).parent().name.(text() == bob).parent()

 but the parent() part seems to be wrong.

 Any ideas???

 On a slightly different note...

 I notice that rootXML.group.(name == fred) will only work for a group
 containing fred and nothing else. Using rootXML.group.name.(text() ==
 fred) sort of gives me what I want, but I really want the parent()
 elements. Of course, I could iterate over the results but I really want to
 do this in one expression.
 --
 View this message in context:
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19604364.html
 Sent from the FlexCoders mailing list archive at Nabble.com.

  



Re: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Mark Carter

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 to build an e4x expression at runtime?


Daniel Freiman wrote:
 
 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
 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 expression?

 My guess would be: rootXML.group.name.(text() ==
 fred).parent().name.(text() == bob).parent()

 but the parent() part seems to be wrong.

 Any ideas???

 On a slightly different note...

 I notice that rootXML.group.(name == fred) will only work for a group
 containing fred and nothing else. Using rootXML.group.name.(text() ==
 fred) sort of gives me what I want, but I really want the parent()
 elements. Of course, I could iterate over the results but I really want
 to
 do this in one expression.
 --
 View this message in context:
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19604364.html
 Sent from the FlexCoders mailing list archive at Nabble.com.

  

 
 

-- 
View this message in context: 
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19609288.html
Sent from the FlexCoders mailing list archive at Nabble.com.



Re: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Daniel Freiman
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 10:38 AM, Mark Carter [EMAIL PROTECTED] wrote:


 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 to build an e4x expression at runtime?


 Daniel Freiman wrote:
 
  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]code%40mark.carter.name
 
  wrote:
 
 
  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 expression?
 
  My guess would be: rootXML.group.name.(text() ==
  fred).parent().name.(text() == bob).parent()
 
  but the parent() part seems to be wrong.
 
  Any ideas???
 
  On a slightly different note...
 
  I notice that rootXML.group.(name == fred) will only work for a group
  containing fred and nothing else. Using rootXML.group.name.(text() ==
  fred) sort of gives me what I want, but I really want the parent()
  elements. Of course, I could iterate over the results but I really want
  to
  do this in one expression.
  --
  View this message in context:
 
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19604364.html
  Sent from the FlexCoders mailing list archive at Nabble.com.
 
 
 
 
 

 --
 View this message in context:
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19609288.html
 Sent from the FlexCoders mailing list archive at Nabble.com.

  



Re: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Mark Carter

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 insensitivity...
 
 
 --- In flexcoders@yahoogroups.com, Daniel Freiman [EMAIL PROTECTED] wrote:

 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
  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 expression?
 
  My guess would be: rootXML.group.name.(text() ==
  fred).parent().name.(text() == bob).parent()
 
  but the parent() part seems to be wrong.
 
  Any ideas???
 
  On a slightly different note...
 
  I notice that rootXML.group.(name == fred) will only work for a
 group
  containing fred and nothing else. Using rootXML.group.name.(text() ==
  fred) sort of gives me what I want, but I really want the parent()
  elements. Of course, I could iterate over the results but I really
 want to
  do this in one expression.
  --
  View this message in context:
 
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19604364.html
  Sent from the FlexCoders mailing list archive at Nabble.com.
 
   
 

 
 
 
 

-- 
View this message in context: 
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19609869.html
Sent from the FlexCoders mailing list archive at Nabble.com.



Re: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Daniel Freiman
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. 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 insensitivity...
 
 
  --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com,
 Daniel Freiman [EMAIL PROTECTED] wrote:
 
  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
   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 expression?
  
   My guess would be: rootXML.group.name.(text() ==
   fred).parent().name.(text() == bob).parent()
  
   but the parent() part seems to be wrong.
  
   Any ideas???
  
   On a slightly different note...
  
   I notice that rootXML.group.(name == fred) will only work for a
  group
   containing fred and nothing else. Using rootXML.group.name.(text() ==
   fred) sort of gives me what I want, but I really want the parent()
   elements. Of course, I could iterate over the results but I really
  want to
   do this in one expression.
   --
   View this message in context:
  
 
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19604364.html
   Sent from the FlexCoders mailing list archive at Nabble.com.
  
  
  
 
 
 
 
 

 --
 View this message in context:
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19609869.html
 Sent from the FlexCoders mailing list archive at Nabble.com.

  



Re: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Mark Carter

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 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
 

-- 
View this message in context: 
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19610183.html
Sent from the FlexCoders mailing list archive at Nabble.com.



Re: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Mark Carter

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 exactly one child name element.


Daniel Freiman wrote:
 
 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. 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 insensitivity...
 
 
  --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com,
 Daniel Freiman [EMAIL PROTECTED] wrote:
 
  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
   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 expression?
  
   My guess would be: rootXML.group.name.(text() ==
   fred).parent().name.(text() == bob).parent()
  
   but the parent() part seems to be wrong.
  
   Any ideas???
  
   On a slightly different note...
  
   I notice that rootXML.group.(name == fred) will only work for a
  group
   containing fred and nothing else. Using rootXML.group.name.(text()
 ==
   fred) sort of gives me what I want, but I really want the parent()
   elements. Of course, I could iterate over the results but I really
  want to
   do this in one expression.
   --
   View this message in context:
  
 
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19604364.html
   Sent from the FlexCoders mailing list archive at Nabble.com.
  
  
  
 
 
 
 
 

 --
 View this message in context:
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19609869.html
 Sent from the FlexCoders mailing list archive at Nabble.com.

  

 
 

-- 
View this message in context: 
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19610549.html
Sent from the FlexCoders mailing list archive at Nabble.com.



Re: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Daniel Freiman
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 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 exactly one child name element.


 Daniel Freiman wrote:
 
  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]code%40mark.carter.name
 
  wrote:
 
 
  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 insensitivity...
  
  
   --- In flexcoders@yahoogroups.com 
   flexcoders%40yahoogroups.comflexcoders%
 40yahoogroups.com,

  Daniel Freiman [EMAIL PROTECTED] wrote:
  
   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
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 expression?
   
My guess would be: rootXML.group.name.(text() ==
fred).parent().name.(text() == bob).parent()
   
but the parent() part seems to be wrong.
   
Any ideas???
   
On a slightly different note...
   
I notice that rootXML.group.(name == fred) will only work for a
   group
containing fred and nothing else. Using rootXML.group.name.(text()
  ==
fred) sort of gives me what I want, but I really want the
 parent()
elements. Of course, I could iterate over the results but I really
   want to
do this in one expression.
--
View this message in context:
   
  
 
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19604364.html
Sent from the FlexCoders mailing list archive at Nabble.com.
   
   
   
  
  
  
  
  
 
  --
  View this message in context:
 
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19609869.html
  Sent from the FlexCoders mailing list archive at Nabble.com.
 
 
 
 
 

 --
 View this message in context:
 http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19610549.html
 Sent from the FlexCoders mailing list archive at Nabble.com.

  



Re: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Mark Carter

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 as a string simply do: name.text()[0].toString()
 

-- 
View this message in context: 
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19611043.html
Sent from the FlexCoders mailing list archive at Nabble.com.



RE: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Tracy Spratt
This is not a direct answer to your immediate question , but rather a
general tip:

If you need complex calculations within an e4x expression, you can call
out to a function of your own.  The () just requires a boolean value, so
you can do something like below, where I wanted to a bit of string
manipulation within the expression:

xlFilteredItems =
_xmlData..item.(itemContains(attribute(item),sFilterString))

 

and the function:

  private function itemContains(sItem:String, sMatch:String):Boolean

  {

sItem = sItem.toLowerCase();

sMatch = sMatch.toLowerCase();

return (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 based on
multiple child conditions

 


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 as a string simply do: name.text()[0].toString()
 

-- 
View this message in context:
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple
-child-conditions-tp19604364p19611043.html
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multipl
e-child-conditions-tp19604364p19611043.html 
Sent from the FlexCoders mailing list archive at Nabble.com.

 



RE: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Mark Carter

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));

  // 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 matchIndex:int =
filters.indexOf(nameElement.toString().toLowerCase());
  var matchedFilter:String = filters[matchIndex];
  if (matchedFilters.indexOf(matchedFilter)  0) { // in case name
appears multiple times in the group
matchedFilters.push(matchedFilter);
  }
}
return matchedFilters.length() == filters.length();
  }


Tracy Spratt wrote:
 
 This is not a direct answer to your immediate question , but rather a
 general tip:
 
 If you need complex calculations within an e4x expression, you can call
 out to a function of your own.  The () just requires a boolean value, so
 you can do something like below, where I wanted to a bit of string
 manipulation within the expression:
 
 xlFilteredItems =
 _xmlData..item.(itemContains(attribute(item),sFilterString))
 
  
 
 and the function:
 
   private function itemContains(sItem:String, sMatch:String):Boolean
 
   {
 
 sItem = sItem.toLowerCase();
 
 sMatch = sMatch.toLowerCase();
 
 return (sItem.indexOf(sMatch) != -1);
 
   }//contains
 
  
 
 Tracy
 

-- 
View this message in context: 
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19620894.html
Sent from the FlexCoders mailing list archive at Nabble.com.



RE: [flexcoders] e4x problem - filtering elements based on multiple child conditions

2008-09-22 Thread Mark Carter

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 matchIndex:int =
filters.indexOf(nameElement.toString().toLowerCase());
  if (matchIndex = 0) {
var matchedFilter:String = filters[matchIndex];
if (matchedFilters.indexOf(matchedFilter)  0) { // in case name
appears multiple times in the group
  matchedFilters.push(matchedFilter);
}
  }
}
return matchedFilters.length() == filters.length();
  }


Mark Carter wrote:
 
 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));
 
   // 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 matchIndex:int =
 filters.indexOf(nameElement.toString().toLowerCase());
   var matchedFilter:String = filters[matchIndex];
   if (matchedFilters.indexOf(matchedFilter)  0) { // in case name
 appears multiple times in the group
 matchedFilters.push(matchedFilter);
   }
 }
 return matchedFilters.length() == filters.length();
   }
 
 
 Tracy Spratt wrote:
 
 This is not a direct answer to your immediate question , but rather a
 general tip:
 
 If you need complex calculations within an e4x expression, you can call
 out to a function of your own.  The () just requires a boolean value, so
 you can do something like below, where I wanted to a bit of string
 manipulation within the expression:
 
 xlFilteredItems =
 _xmlData..item.(itemContains(attribute(item),sFilterString))
 
  
 
 and the function:
 
   private function itemContains(sItem:String, sMatch:String):Boolean
 
   {
 
 sItem = sItem.toLowerCase();
 
 sMatch = sMatch.toLowerCase();
 
 return (sItem.indexOf(sMatch) != -1);
 
   }//contains
 
  
 
 Tracy
 
 
 

-- 
View this message in context: 
http://www.nabble.com/e4x-problem---filtering-elements-based-on-multiple-child-conditions-tp19604364p19621698.html
Sent from the FlexCoders mailing list archive at Nabble.com.



[flexcoders] e4x problem

2007-10-30 Thread reflexactions
Just curious ... i am passing an xml node into a function, says its 
called data, and has a structure
aaa
  bbb
  bbb
  bbb
aaa

In the debugger i can type data[0] and I correctly get the value of 
the [0] child .

But in actionscript it returns the whole node as data[0] refers 
to aaa not its children so I have to use aaa.bbb[0] to get what I 
want.

What I was trying to do was have a simple way that would work for 
getting an attribute, a node or an item in a xmllist ie [@z], 
[ccc], [0] .. with the name of what I am going to pull out being 
also passed as a param and it works in the debugger but not in code :)





[flexcoders] e4x problem

2007-05-17 Thread quinrou
Hi,

I am having problem to retreive data from nodes that contains colon
with the e4x format.

If you consider the following node:
config
  item
media:thumbnail url=http://someurl/something.png; /
  /item
/config

how would you then access the data contain by the url attribute?

Many Thanks

Seb



Re: [flexcoders] e4x problem

2007-05-17 Thread khair

Does your XML document have a  xmlns:thumbnail attribute in it?
Your XML document might not be formed well.

--Keith H--



 Hi,
 
 I am having problem to retreive data from nodes that contains colon
 with the e4x format.
 
 If you consider the following node:
 config
  item
media:thumbnail url=http://someurl/something.png; /
  /item
 /config
 
 how would you then access the data contain by the url attribute?
 
 Many Thanks
 
 Seb