Builder::XmlMarkup extra to_s tag

T

ted

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
 
R

Rob Biedenharn

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"
f = File.new("test.xml", "w")
xml = Builder::XmlMarkup.new:)target=>f, :indent=>2)
xml.fruit do
xml.name(fruit.name)
end


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


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 Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
T

ted

thanks Rob.


Rob Biedenharn said:
xml = Builder::XmlMarkup.new:)target=>f, :indent=>2)

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 Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top