REXML Formatting issues

Posted by dagda1 on Stack Overflow See other posts from Stack Overflow or by dagda1
Published on 2009-05-07T10:42:50Z Indexed on 2010/04/11 2:03 UTC
Read the original article Hit count: 263

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rexml