XML Builder - why?

Discussion in 'Ruby' started by eastcoastcoder@gmail.com, Feb 16, 2006.

  1. Guest

    I see that a lot of Rubyists like using XML Builder to generate XML.
    why took this even further with markaby to generate HTML.

    My question is: why? In what way is Builder any easier, clearer, more
    succint than simpling using an ERB template? I find that Builder is
    about the same length, with about the same structure, only introducing
    an extra conversion. For what?

    The reason I'm asking is that I see that a lot of bright, experienced
    Ruby programmers use it, and I'm wondering if I'm missing something or
    not.
    , Feb 16, 2006
    #1
    1. Advertising

  2. James Britt Guest

    wrote:
    > I see that a lot of Rubyists like using XML Builder to generate XML.
    > why took this even further with markaby to generate HTML.
    >
    > My question is: why? In what way is Builder any easier, clearer, more
    > succint than simpling using an ERB template? I find that Builder is
    > about the same length, with about the same structure, only introducing
    > an extra conversion. For what?


    Uses plain Ruby. No '<' '>" thingies. Automagic encoding of special
    characters. Less chance of error. Focus on structure and logic, not
    incidentals of the markup format.

    Sure, for smallish things it may be overkill, but otherwise it is quite
    handy, especially for the angle-bracket-phobic

    >
    > The reason I'm asking is that I see that a lot of bright, experienced
    > Ruby programmers use it, and I'm wondering if I'm missing something or
    > not.


    Perhaps not. Season to taste.


    --
    James Britt

    http://www.ruby-doc.org - Ruby Help & Documentation
    http://www.artima.com/rubycs/ - The Journal By & For Rubyists
    http://www.rubystuff.com - The Ruby Store for Ruby Stuff
    http://www.jamesbritt.com - Playing with Better Toys
    http://www.30secondrule.com - Building Better Tools
    James Britt, Feb 16, 2006
    #2
    1. Advertising

  3. On Thu, Feb 16, 2006 at 03:33:27PM +0900, wrote:
    > I see that a lot of Rubyists like using XML Builder to generate XML.
    > why took this even further with markaby to generate HTML.
    >
    > My question is: why? In what way is Builder any easier, clearer, more
    > succint than simpling using an ERB template? I find that Builder is
    > about the same length, with about the same structure, only introducing
    > an extra conversion. For what?


    I like that the ruby parser checks the well-formedness of my markup for
    me.


    dave

    --
    http://david.holroyd.me.uk/
    David Holroyd, Feb 16, 2006
    #3
  4. On Thursday 16 February 2006 1:33 am, wrote:
    > I see that a lot of Rubyists like using XML Builder to generate XML.
    > why took this even further with markaby to generate HTML.


    Well, I don't really use Builder for HTML, but generate quite a lot of
    XML with it. Here's one simple use I like (make XSLT search-and-replace
    with simple YAML):

    #!/usr/bin/env ruby
    require 'yaml'
    require 'rubygems'
    require_gem 'builder', '~> 1.2'

    ARGV.each do |arg|
    yml = YAML::load(File.open(arg))

    b = Builder::XmlMarkup.new:)target => STDOUT,
    :indent => 2)
    b.xsl :stylesheet, "version" =>"1.0",
    "xmlns:xsl"
    =>"http://www.w3.org/1999/XSL/Transform" do
    b.xsl :eek:utput, "method" =>"xml", "encoding"=>"ascii",
    "cdata-section-elements=>"_facet"

    b.comment!("Default Rule")
    b.xsl :template, "match"=>"@*|node()" do
    b.xsl :copy do
    b.xsl :"apply-templates", "select"=>"@*|node()"
    end # xsl:template
    end # xsl:copy

    yml.each { |outkey, outvalue|
    outvalue.each { |key, value|
    b.xsl :template, "match"=>"#{outkey}[. =
    &quot;`#{key}&apos;&quot;]" do
    b.xsl :copy, "`#{value}'"
    # b.xsl :message, "Matched #{key}"
    end
    } # end of outvalue.each
    } # end of yaml.each
    end
    end
    Keith Fahlgren, Feb 16, 2006
    #4
    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. Bassa
    Replies:
    0
    Views:
    973
    Bassa
    Sep 19, 2003
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    862
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,762
    Smokey Grindel
    Dec 2, 2006
  4. Tricky

    Why use DSP builder over HDL?

    Tricky, Oct 2, 2009, in forum: VHDL
    Replies:
    8
    Views:
    1,703
  5. Phlip
    Replies:
    5
    Views:
    550
    Stefan Behnel
    Jan 13, 2010
Loading...

Share This Page