Forum: Ruby Builder::XmlMarkup extra to_s tag

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
ted (Guest)
on 2008-10-09 15:15
(Received via mailing list)
Hi,

I'm trying to print out some xml and don't know what I'm doing. I'm
getting
this <to_s/> tag in the output. Where is it coming from and how do I get
rid
of it. Here's my test code. Any help appreciated.

CODE:
require "builder"
class Fruit
 attr_accessor :name
end
fruit = Fruit.new()
fruit.name = "Apple"
xml = Builder::XmlMarkup.new(:indent=>2)
xml.fruit do
 xml.name(fruit.name)
end
f = File.new("test.xml", "w")
f.print(xml)

OUTPUT:
<fruit>
  <name>Apple</name>
</fruit>
<to_s/>


Thanks,
Ted
Rob B. (Guest)
on 2008-10-09 16:07
(Received via mailing list)
On Oct 9, 2008, at 7:12 AM, ted wrote:

> class Fruit
>   attr_accessor :name
> end
> fruit = Fruit.new()
> fruit.name = "Apple"
> f = File.new("test.xml", "w")
xml = Builder::XmlMarkup.new(:target=>f, :indent=>2)
>
>
> Thanks,
> Ted

or change your original to:
f.print(xml.target!)
The to_s comes from print getting something that is not a String and
coercing it with to_s which the Builder object thinks is an empty tag.

-Rob

Rob B.    http://agileconsultingllc.com
removed_email_address@domain.invalid
ted (Guest)
on 2008-10-12 06:47
(Received via mailing list)
thanks Rob.


"Rob B." <removed_email_address@domain.invalid> wrote in message
news:removed_email_address@domain.invalid...
This topic is locked and can not be replied to.