Forum: Ruby Update existing doc with REXML

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
67c5ff1f6ed847f819edac651f82943f?d=identicon&s=25 peri (Guest)
on 2007-07-11 15:32
(Received via mailing list)
I have been searching around the forums and the documentation, but I
do not see any examples/topics on how to open an existing XML document
and update a value (element's text value, for example) using REXML.
Is it even possible?  All I have for a workaround is overwriting the
existing file using document.write.  Am I missing something obvious

Below is an example I am trying to work with:
doc ='cars.xml')

doc.root.each_element("//vehicle[make='Ford']") do |file_node|
  file_node.elements['method'].text = "U"
end'cars.xml','w') do |f|
  f.write doc.write
8310c5a7c769345114597bcdef111488?d=identicon&s=25 (Guest)
on 2007-07-11 15:38
(Received via mailing list)
Hmm, Document#write takes the output stream as an argument... so, I
think you want:


Hope that helps,

This topic is locked and can not be replied to.