Created
June 9, 2016 10:38
-
-
Save akostadinov/f450c1282cd10e2045befc70db9c506a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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