Skip to content

Instantly share code, notes, and snippets.

@DanielHeath
Created October 28, 2010 00:58
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 DanielHeath/650369 to your computer and use it in GitHub Desktop.
Save DanielHeath/650369 to your computer and use it in GitHub Desktop.
require 'nokogiri'
src = <<-XML
<office:text
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">
<text:p>one <text:span>span</text:span></text:p>
<text:p>two</text:p>
</office:text>
XML
dest = <<-XML
<office:document-content
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">
<office:body>
<office:text></office:text>
</office:body>
</office:document-content>
XML
text_p_node = Nokogiri::XML(src).at_xpath('//text:p')
target_node = Nokogiri::XML(dest).at_xpath('//office:text')
target_node.add_child(text_p_node)
puts target_node.to_xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment