title: Can I use a plaintext diff algorithm for tracking XML changes?
body: <p>I'm working in Flex/AS3 on (for simplicity) an XML editor.  I need to provide undo/redo functionality.</p>
  
  <p>Of course, one solution is to store the entire source text with each edit.  However, to conserve memory, I'd like to store the diffs instead (these diffs will also be used to transmit updates to the server for auto-saving).</p>
  
  <hr>
  
  <p><strong>My question is - can I use a plaintext diff algorithm for tracking these XML changes?</strong></p>
  
  <p>My research on the internet indicates that I <em>cannot</em> do so.  However, I'm obviously missing something.  Plaintext diff provides functionality that is purportedly:</p>
  
  <pre><code>diff(text, text') -&gt; diffs
  patch(text, diffs) -&gt; text'
  </code></pre>
  
  <p>XML is simply text, so why can't I just use diff() and patch() to transform the text reliably?</p>
  
  <p>For example: Let's say that I'm a poet.  When I write poetry, I use lots of funky punctuation... You know, like &lt;, /, and >.  (You might see where I'm going with this...)  If I'm writing my poetry in an application that uses diffs to provide undo/redo functionality, does my poetry become garbled when I undo/redo my edits?  It's just text!  Why does it make a difference to the algorithm?</p>
  
  <p>I obviously don't get something here...Thanks for explaining! :)</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Some discussion I've encountered regarding diffing XML with a plaintext algorithm:</p>
  
  <ul>
  <li><a href="http://code.google.com/p/google-diff-match-patch/wiki/Plaintext" rel="nofollow noreferrer">http://code.google.com/p/google-diff-match-patch/wiki/Plaintext</a></li>
  <li><a href="https://stackoverflow.com/questions/2132914/is-there-a-js-diff-library-against-htmlstring-just-like-google-diff-match-patch-o">Is there a JS diff library against htmlstring just like google-diff-match-patch on plain text?</a></li>
  </ul>
  
  <hr>
  
  <p>Also, I understand that a Command pattern is likely a better way to implement Undo/Redo.  I've simplified my use case for the sake of simplicity, and I do still think that XML diffing is the best approach.</p>