Skip to content

Instantly share code, notes, and snippets.

@tinhajj
Created August 26, 2016 18:50
Show Gist options
  • Save tinhajj/95a2d97acd35d610cec4eb61845af4b0 to your computer and use it in GitHub Desktop.
Save tinhajj/95a2d97acd35d610cec4eb61845af4b0 to your computer and use it in GitHub Desktop.
nokogiri/diff issue
<root>
<leaf1>
<subleaf id="test"></subleaf>
</leaf1>
<leaf2>
<subleaf got="game">text</subleaf>
<subleaf id="hello">inside</subleaf>
</leaf2>
</root>
<root>
<leaf2>
<subleaf id="hello">inside</subleaf>
<subleaf got="game">text</subleaf>
</leaf2>
<leaf1>
<subleaf id="test"></subleaf>
</leaf1>
</root>
require 'nokogiri'
require 'nokogiri/diff'
xml_doc1 = File.open("first.xml") { |f| Nokogiri::XML(f) }
xml_doc2 = File.open("second.xml") { |f| Nokogiri::XML(f) }
xml_doc1.diff(xml_doc2, { added: 'true' }) do |change, node|
p "#{change} #{node}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment