Class | REXMLBuilder |
In: |
lib/facets/more/rexmlbuilder.rb
|
Parent: | Object |
Build XML Documents programatically with Ruby and REXML via the Builder Pattern —made possible by Ruby‘s blocks.
XmlBuilder uses REXML to contruct XML documents, helping to ensure XML specification conforamcy.
x = REXMLBuilder.new favs = [ 'cake', 'jelly', 'salt' ] x.table( :width=>'100%' ) { x.tr { favs.each { |v| x.td v } } } }
You can also setup the XmlBuilder to assume an implicit self, so the explict reciever is not needed.
x = REXMLBuilder.new( :implicit ) x.table( :width=>'100%' ) { tr { td "1" ; td "2" ; td "3" } } }
Implict building is more elegant in form, but it is not as functional because it makes it more difficult to refer to external values, ie. if ‘favs’ were used as in the previous example, it would be interpreted as another tag entry, not the array.