PDA

View Full Version : filterFunction versus xpath


Austrian Pine
04-07-2008, 11:28 PM
I'm a newbie. I have a DataGrid backed by XML data. As the user selects a category of data, I need to filter what's seen in the list.

One option is to bind the data grid to an XMLList variable, and simply overwrite the XMLList reference via a simple xpath statement. In other words, the user selects a category, and I run an event handler that runs a single xpath select on the original XML. This returns a new XMLList which I assign to the bound field -- very clean and simple.

The alternative is to use a XMLListCollection for the grid's dataProvider and update it via a filterFunction. I.e., when the user selects a category, I'd run refresh on the XMLListCollection, which would fire my filterFunction.

So it looks like there are two ways to do the same thing. Which is better?

kahuja
04-08-2008, 08:36 AM
I would go for Option#2, use of objects is always fast.

kahuja
04-08-2008, 08:37 AM
I also recommended the same to someone just a min back (http://www.actionscript.org/forums/showthread.php3?p=728807&posted=1#post728807)

Austrian Pine
04-08-2008, 07:58 PM
I would go for Option#2, use of objects is always fast.

Thanks for the response, but I don't follow your logic. Is the e4x xpath expression evaluator inefficient?

Using xpath, the e4x xpath implementation will evaluate my expression, loop around, and return an XMLList result. Using XMLListCollection and a filter, the XMLListCollection refresh method builds an internal array by looping through the original collection and passing each XML element to my filter function.

Off hand, the xpath solution seems better because e4x is designed for selecting nodes. But as I said, I'm a newbie, so maybe there's some advantage to XMLListCollection/filters that I should be aware of. Do you have any more information that would help me make a decision?

kahuja
04-08-2008, 08:43 PM
I am coming form OO background J2EE and C#.net where we work on objects and use of XML/XPath was always slow - that was my starting point some time back when I started to look at AS3. Upon some reads, I came to a conclusion that objects/collections would be a better option that use of XPath.

Note: I have not evaluated these two together and do not have a strong opinion on this. I have to take up some performance metrics for my project and would be evaluating some of these techniques, but that will take time.

My $0.02.