Skip to content

Instantly share code, notes, and snippets.

@akostadinov
Created June 9, 2016 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akostadinov/f450c1282cd10e2045befc70db9c506a to your computer and use it in GitHub Desktop.
Save akostadinov/f450c1282cd10e2045befc70db9c506a to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# see https://github.com/sparklemotion/nokogiri/issues/1200
require 'nokogiri'
src =<<EOD
<wrapper xmlns="ns">
<record xml:id="r1" xmlns:extra="extra">
<field>aaa</field>
<field extra:type="second">bbb</field>
</record>
</wrapper>
EOD
src_doc = Nokogiri::XML(src)
record = src_doc.at('//base:record', {'base' => "ns"})
puts "== Original document"
puts src_doc.to_xml
# we need record.dup to see a second record below
src_doc.root.add_child(record)
puts
puts "== New document"
puts "== Where is my second record?!!"
puts src_doc.to_xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment