Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Builder::XmlMarkup extra to_s tag

Reply
Thread Tools

Builder::XmlMarkup extra to_s tag

 
 
ted
Guest
Posts: n/a
 
      10-09-2008
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



 
Reply With Quote
 
 
 
 
Rob Biedenharn
Guest
Posts: n/a
 
      10-09-2008

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://agileconsultingllc.com
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
ted
Guest
Posts: n/a
 
      10-12-2008
thanks Rob.


"Rob Biedenharn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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://agileconsultingllc.com
> (E-Mail Removed)
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does return-by-value mean extra copies and extra overhead? mathieu C++ 3 09-04-2009 04:25 PM
Extra space between form tag and table tag when screen resolution is 1280 x 1024 nikkilou@nycap.rr.com HTML 2 07-24-2007 11:29 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Rendering extra tags inside an XHTML-MP <head> tag Leonardo Constantino ASP .Net Mobile 0 08-08-2004 04:57 AM
Array and Hash to_s Ben Giddings Ruby 1 07-20-2003 05:06 PM



Advertisments