I'm working in Flex/AS3 on (for simplicity) an XML editor. I need to provide undo/redo functionality.
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).
My question is - can I use a plaintext diff algorithm for tracking these XML changes?
My research on the internet indicates that I cannot do so. However, I'm obviously missing something. Plaintext diff provides functionality that is purportedly:
diff(text, text') -> diffs
patch(text, diffs) -> text'
XML is simply text, so why can't I just use diff() and patch() to transform the text reliably?
For example: Let's say that I'm a poet. When I write poetry, I use lots of funky punctuation... You know, like <, /, 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?
I obviously don't get something here...Thanks for explaining! :)
UPDATE:
Some discussion I've encountered regarding diffing XML with a plaintext algorithm:
- http://code.google.com/p/google-diff-match-patch/wiki/Plaintext
- Is there a JS diff library against htmlstring just like google-diff-match-patch on plain text?
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.