[Nokogiri-talk] We need a better XML Builder!

Aaron Patterson aaron.patterson at gmail.com
Thu Mar 5 22:21:41 EST 2009


On Thu, Mar 5, 2009 at 4:22 PM, Julien Genestoux
<julien.genestoux at gmail.com> wrote:
> Hey,
>
> I don't knwo about you but I am having a lot of trouble with Nokogiri's
> Builder; It's not that it's not working, but I just find the syntax counter
> intuitive : why would we need to build the whole XML in a block? It makes it
> difficult to pass variables (through @context).
>
> So, why not re-using Builder's syntax with
> xml = Nokogiri::Builder.new
> xml.tag do
>     xml.subtag(:attr => "myvalue")
> end

Thanks for the feedback!  I'd rather not do the syntax you just
spelled out because it means that I would have to keep track of depths
and block calls.  What do you think of something like this?

        string = "hello world"
        builder = Nokogiri::XML::Builder.new
        builder.root { |root|
          root.cdata string
        }

It's very easy to implement, only 3 line change.  I *think* it gets
you what you need.  Let me know!

-- 
Aaron Patterson
http://tenderlovemaking.com/


More information about the Nokogiri-talk mailing list