Featured Posts

Adobe Flex - Filter XML Data using E4X and RegExp Have you ever you wanted to filter your data like you would using the SQL LIKE condition? Well with E4X and RegExp you too can reap the benefits of pattern matching! Here...

Readmore

Flex Assets/File Manager – ASP VBScript - Version... I recently built a JavaScript file manager but I wanted more control and better usability instead of expanding on the JavaScript version I decided to build it using Flex....

Readmore

Getting at your SQL Database using Flex and .NET Web ServicesGetting at your SQL Database using Flex and .NET Web... So you gave up on trying to figure out how you can directly connect Flex to your database like with any server side language and decided to Google the answer. Well by now...

Readmore

Adobe Flex - Filter XML Data using E4X and RegExp Have you ever you wanted to filter your data like you would using the SQL LIKE condition? Well with E4X and RegExp you too can reap the benefits of pattern matching! Here...

Readmore

Fitchett Rss

Adobe Flex – Filter XML data using E4X

Posted on : 31-03-2009 | By : Michael Fitchett | In : Flex, Quick Tips

2

find1You have imported your data using either an HTTPService, Web Service or some other means. Great! now how do you filter and sort the data? Using E4X of course! Lets get started.

1st. Switch the resultFormat on your HTTPService or Web Service by adding the following property resultFormat=”e4x” to your tag:

<!-- HTTPService -->
<mx:HTTPService id='data' resultFormat="e4x"/>
<!-- Web Service -->
<mx:WebService id="wsData" wsdl="http://www.domain.com/Service.asmx?WSDL" showBusyCursor="true">
      <mx:operation name="getData" resultFormat="e4x">


2nd. Now that we are returning the XML data in E4x format we can now use E4x to filter the data. Here is a quick example of how you would filter the data in a DataGrid:

<!-- HTTPService -->
<mx:DataGrid dataProvider="{data.lastResult.root.item(somenode != null)}"/>
<!-- Return One Record/Row/Result-->
<mx:DataGrid dataProvider="{data.lastResult.root.item(somenode != null)[0]}"/>
<!-- Web Service -->
<mx:DataGrid dataProvider="{wsData. getData.lastResult.root.item(somenode != null)}"/>
<!-- Return One Record/Row/Result-->
<mx:DataGrid dataProvider="{wsData. getData.lastResult.root.item(somenode != null)[0]}"/>

This is just one way of doing it, you have tons of different options. It all really depends on your project; typically, I bind the data to an XMLListCollection then filter the data by changing the source with the filter code and running refresh on the XMLListCollection.

http://www.fitchett.me/wp-content/plugins/sociofluid/images/digg_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/delicious_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/technorati_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/google_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/myspace_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/facebook_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/twitter_32.png

Comments (2)

Michael, I just need a simple E4X datagrid example.

Can you help us out?

All we want to do is

1) use HTTPService to get data remotely
2) with resultFormat = “e4x”

and then

3) populate a two-or-three-column datagrid with the XML data
4) without arrayCollection
5) straight from XML

For the last two days, I have been struggling with the syntax. Everything works fine until I start using E4X. The XML displays properly in another application, where I’m using the default resultFormat (object).

Since Adobe and other FLEX gurus claim that using E4X is the best approach to dealing with XML files — but nobody provides a simple example — I was hoping that somebody here could tell me how it’s done. From what I’ve been able to find out, there are many other Flex developers who have a hard time with that as well.

Thanks for any ideas or links, etc.

I just went live with a post that should help you http://www.fitchett.me/?p=177

Write a comment

Spam Protection by WP-SpamFree

Advertise Here