Skip to content

Instantly share code, notes, and snippets.

@cgdangelo
Created October 5, 2012 17:20
Show Gist options
  • Save cgdangelo/3841125 to your computer and use it in GitHub Desktop.
Save cgdangelo/3841125 to your computer and use it in GitHub Desktop.
require 'nokogiri'
document = Nokogiri::XML(File.read('app/etc/local.xml'))
child_node = Nokogiri::XML::Node.new("test_child", document))
child_node.content = "foo"
document.xpath('config/global/resources/default_setup/connection')[0].add_child(child_node)
File.open('app/etc/local.xml.modified', 'w') { |f| document.write_xml_to f }
# <config>
# <global>
# <resources>
# <default_setup>
# <connection>
# ...
# <test_child>foo</test_child>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment