[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Builder::XmlMarkup extra to_s tag

ted

10/9/2008 9:12:00 AM

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



2 Answers

Rob Biedenharn

10/9/2008 12:04:00 PM

0


On Oct 9, 2008, at 7:12 AM, ted wrote:

> 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://agileconsult...
Rob@AgileConsultingLLC.com


ted

10/12/2008 2:40:00 AM

0

thanks Rob.


"Rob Biedenharn" <Rob@AgileConsultingLLC.com> wrote in message
news:FF3BC3A8-4734-452F-959A-463A5E5DBBC7@AgileConsultingLLC.com...
>
> On Oct 9, 2008, at 7:12 AM, ted wrote:
>
>> 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://agileconsult...
> Rob@AgileConsultingLLC.com
>
>