Builder::XmlMarkup extra to_s tag

Discussion in 'Ruby' started by ted, Oct 9, 2008.

  1. ted

    ted Guest

    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
    ted, Oct 9, 2008
    #1
    1. Advertising

  2. 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
    Rob Biedenharn, Oct 9, 2008
    #2
    1. Advertising

  3. ted

    ted Guest

    thanks Rob.


    "Rob Biedenharn" <> wrote in message
    news:...
    >
    > 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
    >
    >
    >
    ted, Oct 12, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    746
    John C. Bollinger
    Jan 27, 2006
  2. Andrew Cox

    Combining XmlMarkup objects?

    Andrew Cox, Jun 9, 2005, in forum: Ruby
    Replies:
    2
    Views:
    185
    Andrew Cox
    Jun 10, 2005
  3. Daniel Sheppard
    Replies:
    0
    Views:
    145
    Daniel Sheppard
    Oct 28, 2005
  4. M. Ayhan
    Replies:
    0
    Views:
    75
    M. Ayhan
    Dec 3, 2008
  5. Raimon Fs
    Replies:
    0
    Views:
    110
    Raimon Fs
    Jun 19, 2010
Loading...

Share This Page