The Lorax is a full diff and patch library for XML/HTML documents, based on Nokogiri.
It can tell you whether two XML/HTML documents are identical, or if they're not, tell you what's different. In trivial cases, it can even apply the patch.
It's based loosely on Gregory Cobena's master's thesis paper, which generates deltas in less than O(n * log n) time, accepting some tradeoffs in the size of the delta set. You can find his paper at gregory.cobena.free.fr/www/Publications/thesis.html.
“I am the Lorax, I speak for the trees.”
Features / Problems
Detect differences between documents, or tell whether two documents are the same.
Generate patches for the differences between documents.
Apply patches for trivial cases.
More work needs to be done to make sure patches apply cleanly.
Imagine you have two Nokogiri::XML::Documents. You can tell if they're identical:
::.(doc1.root). == ::.(doc2.root).
You can generate a delta set (currently opaque (sorry kids)):
delta_set = .(doc1, doc2)
and apply the delta set as a patch to the original document:
new_doc = delta_set.apply(doc1)
sudo gem install lorax
(The MIT License)
Copyright © 2009-2012 Mike Dalessio
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.