title: Deleting / Replacing A Node in E4X (AS3 - Flex)
body: <p>I'm building a listing/grid control in a <code>Flex</code> application and using it in a <code>.NET</code> web application.  To make a really long story short I am getting XML from a webservice of serialized objects.  I have a page limit of how many things can be on a page.  I've taken a data grid and made it page, sort across pages, and handle some basic filtering.  </p>
  
  <p>In regards to paging I'm using a Dictionary keyed on the page and storing the XML for that page.  This way whenever a user comes back to a page that I've saved into this dictionary I can grab the XML from local memory instead of hitting the webservice.  Basically, I'm caching the data retrieved from each call to the webservice for a page of data.</p>
  
  <p>There are several things that can expire my cache.  Filtering and sorting are the main reason.  However, a user may edit a row of data in the grid by opening an editor.  The data they edit could cause the data displayed in the row to be stale.  I could easily go to the webservice and get the whole page of data, but since the page size is set at runtime I could be looking at a large amount of records to retrieve.</p>
  
  <p>So let me now get to the heart of the issue that I am experiencing.  In order to prevent getting the whole page of data back I make a call to the webservice asking for the completely updated record (the editor handles saving its data).</p>
  
  <p>Since I'm using custom objects I need to serialize them on the server to XML (this is handled already for other portions of our software).  All data is handled through XML in e4x.  The cache in the Dictionary is stored as an XMLList.</p>
  
  <p><strong>Now let me show you my code...</strong></p>
  
  <pre><code>var idOfReplacee:String = this._WebService.GetSingleModelXml.lastResult.*[0].*[0].@Id;
  var xmlToReplace:XMLList = this._DataPages[this._Options.PageIndex].Data.(@Id == idOfReplacee);
  
  if(xmlToReplace.length() &gt; 0)
  {
      delete (this._DataPages[this._Options.PageIndex].Data.(@Id == idOfReplacee)[0]);
      this._DataPages[this._Options.PageIndex].Data += this._WebService.GetSingleModelXml.lastResult.*[0].*[0];
  }
  </code></pre>
  
  <p>Basically, I get the id of the node I want to replace.  Then I find it in the cache's Data property (<code>XMLList</code>).  I make sure it exists since the filter on the second line returns the <code>XMLList</code>.</p>
  
  <p>The problem I have is with the delete line.  I cannot make that line delete that node from the list.  The line following the delete line works.  I've added the node to the list.</p>
  
  <p>How do I replace or delete that node (meaning the node that I find from the filter statement out of the .Data property of the cache)???</p>
  
  <p>Hopefully the underscores for all of my variables do not stay escaped when this is posted! otherwise <code>this.&amp;#95 == this</code>._</p>