For an internal project (kindof), i had to use E4X to parse my results from a mx:WebService. I really found it a pleasure to work with it. The thing is that WebService class in Flex allows the return type to be “Object“, “xml” or “e4x“. The difference is as follows.
- Using Object – Setting return type as Object, returns data in the form of an ObjectProxy. Below, I have provided the example of a WebService response from Amazon Web Service, inspected in FlexBuilder. As you can see, the ObjectProxy contains several complex datatypes, including ArrayCollection and mx.rpc.xml.ComplexString, which can be tricky to handle. Also you would have to do same parsing logic to parse the incoming result to your liking.
- Using XML – Using an xml return type, returns the data as an Array of XMLNodes as below. I have earlier mentioned the pains of accessing nodes in a legacy XMLDocument way.
- Using E4X : Makes it so much simpler. Gives me an XMLList as the result as below.
What this does for me is that the parsing becomes a cakewalk. I can just do the following and filter out all the Items in my result. res below is a ResutEvent of type mx.rpc.events.ResultEvent.
myXML:XMLList = res.result..Item;
Then, this XMLList variable can be bound to a mx:DataGrid (as DataGrid will internally convert it to an XMLListCollection) and you can work seamlessly with it… What a joy 🙂