Hi All,
I am reading an excel file and then generating a XML file. I am using
the below code. I am using Builder to do soo. Below i thought that as i
have a 'x' object of builder, i can write it to a yaml file using the
dump method.
CODE:
def generate_xml()
x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1)
x.instruct!
x.comment! "A test xml for test cases"
x.FileName "#{@p}"
x.TotalCases "#{@t}"
x.Contents "#{@c}"
File.open('dump.xml','w') {|f| f.write(YAML.dump(x))}
puts "generated xml" #Just to print this in console
end
When i run below i get error -
C:/Ruby193/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:413:in
`dump_coder': undefined method `name' for #<IO:<STDOUT>> (NoMethodError)
OR what could be another approach to generate an xml file?
You are already telling builder to write to $stdout, you shouldn’t even have a File.open in there. Also, the builder object x is not YAMLizable with that target, per se.
What you probably (?) want to be doing is more like this:
f = File.new('dump.xml','w')
x = Builder::XmlMarkup.new(:target => f, :indent => 1)
...
f.close
···
On Nov 4, 2013, at 2:51 AM, Rochit Sen <lists@ruby-forum.com> wrote:
Hi All,
I am reading an excel file and then generating a XML file. I am using
the below code. I am using Builder to do soo. Below i thought that as i
have a 'x' object of builder, i can write it to a yaml file using the
dump method.
CODE:
def generate_xml()
x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1)
x.instruct!
x.comment! "A test xml for test cases"
x.FileName "#{@p}"
x.TotalCases "#{@t}"
x.Contents "#{@c}"
File.open('dump.xml','w') {|f| f.write(YAML.dump(x))}
puts "generated xml" #Just to print this in console
end
When i run below i get error -
C:/Ruby193/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:413:in
`dump_coder': undefined method `name' for #<IO:<STDOUT>> (NoMethodError)
OR what could be another approach to generate an xml file?
If you are building an XML file why are you then converting it to YAML? Why
not write it out as is?
···
On 4 November 2013 08:51, Rochit Sen <lists@ruby-forum.com> wrote:
Hi All,
I am reading an excel file and then generating a XML file. I am using
the below code. I am using Builder to do soo. Below i thought that as i
have a 'x' object of builder, i can write it to a yaml file using the
dump method.
CODE:
def generate_xml()
x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1)
x.instruct!
x.comment! "A test xml for test cases"
x.FileName "#{@p}"
x.TotalCases "#{@t}"
x.Contents "#{@c}"
File.open('dump.xml','w') {|f| f.write(YAML.dump(x))}
puts "generated xml" #Just to print this in console
end
When i run below i get error -
C:/Ruby193/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:413:in
`dump_coder': undefined method `name' for #<IO:<STDOUT>> (NoMethodError)
OR what could be another approach to generate an xml file?
On Nov 4, 2013, at 2:51 AM, Rochit Sen <lists@ruby-forum.com> wrote:
x.comment! "A test xml for test cases"
OR what could be another approach to generate an xml file?
Thanks
You are already telling builder to write to $stdout, you shouldnt even
have a File.open in there. Also, the builder object x is not YAMLizable
with that target, per se.
What you probably (?) want to be doing is more like this:
f = File.new('dump.xml','w')
x = Builder::XmlMarkup.new(:target => f, :indent => 1)
...
f.close
Thanks Tamouse. Dont know why that didnt trigger to me before. Able to
generate a xml now.