title: Flex sorting of XMLListCollection subelements
body: <p>In a Flex webapp, is there an easy way to go about applying a sort to the children of an XML element, based on the children's attributes? Example follows below:</p>
  
  <p>XMLListCollection:</p>
  
  <blockquote>
    <p><code>&lt;a anotherProp="ABCDE"&gt;</code><br/>
      &nbsp;&nbsp;<code>&lt;e prop="AB"&gt;1&lt;/element&gt;</code><br/>
     &nbsp;&nbsp;<code>&lt;e prop="BC"&gt;2&lt;/element&gt;</code><br/>
     <code>&lt;/a&gt;</code><br/>
     <code>&lt;a anotherProp="FGEH"&gt;</code><br/>
      &nbsp;&nbsp;<code>&lt;e prop="HF"&gt;3&lt;/element&gt;</code><br/>
      &nbsp;&nbsp;<code>&lt;e prop="AD"&gt;4&lt;/element&gt;</code><br/>
      &nbsp;&nbsp;<code>&lt;e prop="AC"&gt;5&lt;/element&gt;</code><br/>
     <code>&lt;/a&gt;</code><br/></p>
  </blockquote>
  
  <p>I would like to sort the <code>&lt;e&gt;</code> elements, within each <code>&lt;a&gt;</code> element separately, according to their "prop" attribute. My code for generating the array containing the <code>&lt;a&gt;</code> elements is along the lines of:</p>
  
  <pre><code>for each(var node:XML in initialInput:XMLListCollection){
    if(node.localName()=="a"){
      //I was hoping to be able to sort the &lt;e&gt; children of the node variable here
      xmlListCollectionVar.addItem(node);
    }
  }
  </code></pre>
  
  <p>At the end I would like the <code>&lt;a&gt;</code>'s to remain in their defined order, but their <code>&lt;e&gt;</code> children to be sorted based on the "prop" attribute. So far if I try:</p>
  
  <blockquote>
    <p>node.children().sort=someSortVar</p>
  </blockquote>
  
  <p>where someSortVar has its fields set to:</p>
  
  <blockquote>
    <p>SortFields("e.@prop",...)</p>
  </blockquote>
  
  <p>I get an exception about a null value. Any way to convert the children list to XMLListCollection, sort it and integrate it back into the node variable? Thanks for any replies.</p>