Update existing doc with REXML

P

peri

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
 
B

bmunat

Hmm, Document#write takes the output stream as an argument... so, I
think you want:

doc.write(f)

Hope that helps,

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Overwrite a File (rexml) 2
REXML 19
bug in REXML escape codes 1
ruby / rexml / xpath bug? 7
REXML raw all doesn't seem to work 0
REXML + Gruff: display label problem 0
REXML logging 2
Rexml xpath question 7

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top