Lazy Decoding ‘e4x like’ features with Xml Remoting 4.0

Xml Remoting 4.0If you don't know about my Flash Xml Remoting class, get the low down and read up in the last version here

I had some time recently to finish off some code I have been looking at for a while making the performance on Xml Remoting alot better when dealing with large Xml data. This version may be the last significiant one in a while as it's getting fairly complete now, given that there are no bugs :). The major point of difference which you may notice is a parameter called 'lazyDecoding' for the XmlRemoting class. Bascially what lazyDecoding does is it only parses the object once it has been referenced, in some cases this may not be handy. But if you have a lot of data, which you may not use all of it straight away, then this will give your Flash application a significant performance boost.

Another update to this version was a bug pointed out by a colleague in the last version (3.1). The bug was if the attribute and the inner child node have the same name it doesn't parse correctly as a solution now all attributes parsed are prefixed with an '@' character. So to spell it out if the attribute name is 'id' to reference it use '@id'. Additionally when using lazy decoding and 'for item in' loops there is a specific way to do this, for either nodes or attributes. All other iteration types work as per normal :), if you don't want to do this (the following example) set lazyDecoding to false by default it is true. The example using 'for item in' iteration using lazy decoding is as follows :

Using this XML

  2. <itemsList>
  3. <items id="1" name="blah">
  4. <label>Finally an Amazing Title</label>
  5. <value>tester</value>
  6. </items>
  7. <items id="2" name="blah">
  8. <label>Lastly an Amazing Title</label>
  9. <value>028.50</value>
  10. </items>
  11. <items id="2" name="blah">
  12. <label>The Amazing Title</label>
  13. <value>true</value>
  14. <value>false</value>
  15. </items>
  16. <items id="3" name="blah">
  17. <label>Again an Amazing Title</label>
  18. <value>2007-03-03T14:07:06.346+11:00</value>
  19. </items>
  20. </itemsList>

You can iterate through either attrbutes or nodes with a for item loop like this

  2. var items =[0];
  3. for (var name in items.attributes) {
  4. trace("attribute "+"@"+name+" : "+items["@"+name]);
  5. // will trace : attribute @id : 1
  6. // attribute @name : blah
  7. }
  8. for (var name in items.nodes) {
  9. trace("node "+name+" : "+items[name]);
  10. // will trace : node value : tester
  11. // node label : Finally an Amazing Title
  12. }

You may download the source under GNU Lesser General Public License and examples with the following links below :

  • Online Documentation
  • FLA Examples and Source Code
  • MXP
  • SWC
  • Download Online Documentation
  • Download All 4.0 Source Code
  • Probaly the only things I will be looking at next will be marrying the concepts of E4X further to my Xml Remoting class.