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.
>=20
> CODE:
> def generate_xml()
> x =3D Builder::XmlMarkup.new(:target =3D> $stdout, :indent =3D> 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
>=20
> 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)
>=20
> OR what could be another approach to generate an xml file?
>=20
> Thanks
>=20

You are already telling builder to write to $stdout, you shouldn=92t =
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 =3D File.new('dump.xml','w')
   x =3D Builder::XmlMarkup.new(:target =3D> f, :indent =3D> 1)
   ...
   f.close