I\'m trying to figure out how to open an xml file, search by an id, replace a value in the node and then resave the document.
my xml
First of all, your node_update
is actually a NodeSet, not the Node that you probably think it is. You need a Node
if you want to call inner_html=
on it:
node_update[0].inner_html = 'true'
Then writing out the updated XML is just a bit of standard file manipulating combined with a to_xml
call:
File.open('whatever.xml', 'w') { |f| f.print(doc.to_xml) }
As an aside, your input isn't valid XML. You have a but no
.