Can I use a plaintext diff algorithm for tracking XML changes?

Posted by rinogo on Stack Overflow See other posts from Stack Overflow or by rinogo
Published on 2010-03-12T02:16:22Z Indexed on 2010/03/12 2:37 UTC
Read the original article Hit count: 477

Filed under:
|
|
|
|

Hi all! Interesting question for you here.

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! :)

-Rich

© Stack Overflow or respective owner

Related posts about Xml

Related posts about diff