Announcement (2017-05-07): www.ruby-forum.com is now read-only since I
unfortunately do not have the time to support and maintain the forum any
more. Please see rubyonrails.org/community and ruby-lang.org/en/community
for other Rails- und Ruby-related community platforms.

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
here?
Below is an example I am trying to work with:
#===========================================
doc = Document.new File.read('cars.xml')
doc.root.each_element("//vehicle[make='Ford']") do |file_node|
file_node.elements['method'].text = "U"
end
File.open('cars.xml','w') do |f|
f.write doc.write
end