Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > XML Builder - why?

Reply
Thread Tools

XML Builder - why?

 
 
eastcoastcoder@gmail.com
Guest
Posts: n/a
 
      02-16-2006
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.

 
Reply With Quote
 
 
 
 
James Britt
Guest
Posts: n/a
 
      02-16-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
David Holroyd
Guest
Posts: n/a
 
      02-16-2006
On Thu, Feb 16, 2006 at 03:33:27PM +0900, (E-Mail Removed) 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/


 
Reply With Quote
 
Keith Fahlgren
Guest
Posts: n/a
 
      02-16-2006
On Thursday 16 February 2006 1:33 am, (E-Mail Removed) 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",
"xmlnssl"
=>"http://www.w3.org/1999/XSL/Transform" do
b.xsl 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


 
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
Where's a DOM builder that uses the Builder Pattern to ... buildDOMs? Phlip Python 5 01-13-2010 12:48 PM
ANN: XML builder for Python Jonas Galvez Python 9 07-04-2008 02:30 AM
xml builder not able to create namespaced elements w/attributes?? Stephen Bannasch Ruby 1 07-23-2006 02:36 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Newbie-question: read a xml-config-file in c++ Builder 5 (Xerces) Bassa XML 0 09-19-2003 09:55 AM



Advertisments