REXML Formatting issues
- by dagda1
Hi,
I am using REXML to edit an xml file but have ran into difficulties with formatting.
My original code looked like this:
file = File.new( destination)
doc = REXML::Document.new file
doc.elements.each("configuration/continuity2") do |element|
element.attributes["islive"] = "true"
element.attributes["pagetitle"] = "#{@client.page_title}"
element.attributes["clientname"] = "#{@client.name}"
end
doc.elements.each("configuration/continuity2/plans") do |element|
element.attributes["storebasedir"] = "#{@client.store_dir}"
end
I first of all had to add the following code as REXML was adding single quotes instead of double quotes. I found the following via google:
REXML::Attribute.class_eval( %q^
def to_string
%Q[#@expanded_name="#{to_s().gsub(/"/, '"')}"]
end
^ )
I also have a problem in that REXML is reformatting the document.
are there ways to stop this?
Cheers
Paul