[flexcoders] Re: XMLFiltering by attributes and values

2009-08-17 Thread fatmanchan2009
Ok, thanks, but dont think i explained my self very well

Basically, i have a properties list which stores a object with a name and a 
value, which are both strings. name is the attribute name, so in ur example it 
will be 'id' and the value will be '1'. so knowing that information i should be 
able to filter the xml using them values.

var itemList : XMLList = items
item id='1' quantity='2' type='fruit'
item id='2' quantity='5' type='veg'
item id='3' quantity='6' type='veg'
item id='4' quantity='7' type='fruit'
 /items;

var propertyList : ArrayCollection = new ArrayCollection();
propertyList.addItem({name:'type' , value:'fruit'});

var filterList : XMLList = itemList.item;

for each(var property : Object in propertyList)
{
 filterList = filterList.(attribute(property.name) == property.value);
}

//Output of filterList
item id='1' quantity='2' type='fruit'
item id='4' quantity='7' type='fruit'

So thats the basic idea but always get that error, looking in the API it 
suggests it is possible to filter like that. Well hope this gives a better idea 
of what the problem is. Thank You

Stephen Chan

--- In flexcoders@yahoogroups.com, Preetham Hegde preethamheg...@... wrote:

 what are name and value to _propertiesList ? Is it elements or attributes?
 If it is element then accessing is correct, there is some other problem.
 If it is attribute then should access like this
 pr...@name or pr...@value
 
 To understand difference between element and attribute here is a example
 
 
 *public function callFunc():void{
 
 var total2:Number = 0;
 for each (var prop:XML in myXML.item)
 {
 total2 += pr...@quantity * prop.price;
 }
 
 Alert.show(total2.toString());
 
 
 }
 
 
 public var myXML:XML =
 order
 item id='1' quantity='2'
 menuNameburger/menuName
 price3.95/price
 /item
 item id='2' quantity='2'
 menuNamefries/menuName
 price1.45/price
 /item
 /order;*
 
 
 
 On Mon, Aug 17, 2009 at 4:57 PM, fatmanchan2009 fatmanchan2...@...wrote:
 
 
 
  Hello
 
  Can anyone figure out this problem im currently having, and explain the
  reasons and cause of this proplem.
 
  I have an XML file of track data with a bunch of attributes
 
  track
  item uniqueTrackId=100 albumId=12 trackId=1 genreId=13
  artistId=6584
  ...
  /track
 
  i use this code to execute the filtering on the data, the name is artistId
  and the value is 6584, so the data should come back with all the artists
  with artistId 6584.
 
  var filterData : XMLList = _trackData.item;
 
  for each (var prop : Object in _propertiesList)
  {
  filterData = filterData.(attribute(prop.name) == prop.value);
  }
 
  but i keep getting this exception, when its applyin the filter, so within
  the for loop
 
  TypeError: Error #1006: value is not a function.
 
  So anyone that can figure what the problem is, would be a big help Thank
  You
 
  Stephen Chan
 
   
 
 
 
 
 -- 
 Regards,
 Preetham Hegde
 
 
 ___
 If you only have a hammer, you tend to see every problem as a nail.





[flexcoders] Re: XMLFiltering by attributes and values

2009-08-17 Thread valdhor
I haven't looked at your code too much but what jumped out at me is this line...

filterData = filterData.(attribute(prop.name) == prop.value);

This will try to evaluate attribute as a function with parameter prop.name and 
then compare that to prop.value returning a boolean. So, the upshot is that 
Flex will try to evaluate filterData.true or filterData.false. I'm pretty sure 
that won't work.


--- In flexcoders@yahoogroups.com, fatmanchan2009 fatmanchan2...@... wrote:

 Hello
 
 Can anyone figure out this problem im currently having, and explain the 
 reasons and cause of this proplem.
 
 I have an XML file of track data with a bunch of attributes
 
 track
 item uniqueTrackId=100 albumId=12 trackId=1 genreId=13 
 artistId=6584
 ...
 /track
 
 i use this code to execute the filtering on the data, the name is artistId 
 and the value is 6584, so the data should come back with all the artists with 
 artistId 6584. 
 
 var filterData : XMLList = _trackData.item;
   
 for each (var prop : Object in _propertiesList)
 {
 filterData = filterData.(attribute(prop.name) == prop.value);
 }
 
 but i keep getting this exception, when its applyin the filter, so within the 
 for loop 
 
 TypeError: Error #1006: value is not a function.
 
 So anyone that can figure what the problem is, would be a big help Thank You 
 
 
 Stephen Chan





RE: [flexcoders] Re: XMLFiltering by attributes and values

2009-08-17 Thread Keith Reinfeld
This works well: 

 

var _trackData:XML = track 

item uniqueTrackId=100 albumId=12 trackId=1 genreId=13
artistId=6584/ 

item uniqueTrackId=101 albumId=13 trackId=2 genreId=14
artistId=6580/ 

item uniqueTrackId=102 albumId=14 trackId=3 genreId=15
artistId=6584/ 

item uniqueTrackId=103 albumId=15 trackId=4 genreId=16
artistId=6583/ 

/track; 

 

function doXMLFilter(nodes:XML,att:String,val:String):XMLList{ 

// Returns all node elements with an attribute that equals
value. 

return nodes.elements(*).(@[att.toString()] == val); 

} 

 

var _data:XMLList = doXMLFilter(_trackData,artistId,6584); 

trace(_data.toXMLString()); 

 

- Keith 

 

 

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of valdhor
Sent: Monday, August 17, 2009 11:15 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: XMLFiltering by attributes and values

 

  

I haven't looked at your code too much but what jumped out at me is this
line...

filterData = filterData.(attribute(prop.name) == prop.value);

This will try to evaluate attribute as a function with parameter prop.name
and then compare that to prop.value returning a boolean. So, the upshot is
that Flex will try to evaluate filterData.true or filterData.false. I'm
pretty sure that won't work.

--- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ,
fatmanchan2009 fatmanchan2...@... wrote:

 Hello
 
 Can anyone figure out this problem im currently having, and explain the
reasons and cause of this proplem.
 
 I have an XML file of track data with a bunch of attributes
 
 track
 item uniqueTrackId=100 albumId=12 trackId=1 genreId=13
artistId=6584
 ...
 /track
 
 i use this code to execute the filtering on the data, the name is artistId
and the value is 6584, so the data should come back with all the artists
with artistId 6584. 
 
 var filterData : XMLList = _trackData.item;
 
 for each (var prop : Object in _propertiesList)
 {
 filterData = filterData.(attribute(prop.name) == prop.value);
 }
 
 but i keep getting this exception, when its applyin the filter, so within
the for loop 
 
 TypeError: Error #1006: value is not a function.
 
 So anyone that can figure what the problem is, would be a big help Thank
You 
 
 
 Stephen Chan




image001.jpgimage002.jpg

RE: [flexcoders] Re: XMLFiltering by attributes and values

2009-08-17 Thread Keith Reinfeld
That comment should read:  

 

// Returns all node elements with the named attribute that equals value. 

 

- Keith 

 

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Keith Reinfeld
Sent: Monday, August 17, 2009 1:15 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: XMLFiltering by attributes and values

 

  

This works well: 

 

var _trackData:XML = track 

item uniqueTrackId=100 albumId=12 trackId=1 genreId=13
artistId=6584/ 

item uniqueTrackId=101 albumId=13 trackId=2 genreId=14
artistId=6580/ 

item uniqueTrackId=102 albumId=14 trackId=3 genreId=15
artistId=6584/ 

item uniqueTrackId=103 albumId=15 trackId=4 genreId=16
artistId=6583/ 

/track; 

 

function doXMLFilter(nodes:XML,att:String,val:String):XMLList{ 

// Returns all node elements with an attribute that equals
value. 

return nodes.elements(*).(@[att.toString()] == val); 

} 

 

var _data:XMLList = doXMLFilter(_trackData,artistId,6584); 

trace(_data.toXMLString()); 

 

- Keith 

 

 

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of valdhor
Sent: Monday, August 17, 2009 11:15 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: XMLFiltering by attributes and values

 

  

I haven't looked at your code too much but what jumped out at me is this
line...

filterData = filterData.(attribute(prop.name) == prop.value);

This will try to evaluate attribute as a function with parameter prop.name
and then compare that to prop.value returning a boolean. So, the upshot is
that Flex will try to evaluate filterData.true or filterData.false. I'm
pretty sure that won't work.

--- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ,
fatmanchan2009 fatmanchan2...@... wrote:

 Hello
 
 Can anyone figure out this problem im currently having, and explain the
reasons and cause of this proplem.
 
 I have an XML file of track data with a bunch of attributes
 
 track
 item uniqueTrackId=100 albumId=12 trackId=1 genreId=13
artistId=6584
 ...
 /track
 
 i use this code to execute the filtering on the data, the name is artistId
and the value is 6584, so the data should come back with all the artists
with artistId 6584. 
 
 var filterData : XMLList = _trackData.item;
 
 for each (var prop : Object in _propertiesList)
 {
 filterData = filterData.(attribute(prop.name) == prop.value);
 }
 
 but i keep getting this exception, when its applyin the filter, so within
the for loop 
 
 TypeError: Error #1006: value is not a function.
 
 So anyone that can figure what the problem is, would be a big help Thank
You 
 
 
 Stephen Chan




image001.jpgimage002.jpg