You want the content=
method:
Set the Node’s content to a Text node containing
string
. The string gets XML escaped, not interpreted as markup.
Note that xpath
returns a NodeSet not a single Node, so you need to use at_xpath
or get the single node some other way:
doc = Nokogiri::XML(File.open ("C:\\myfile.xml"))
node = doc.xpath("//Ranch//Street")[0] # use [0] to select the first result
node.content = "New value for this node"
puts doc # produces XML document with new value for the node