SummaryAllows one to programatically create valid XHTML/XML documents
Short namebuilder
Content typetext
Provided by bundlebuilt-in
API docWebgen::ContentProcessor::Builder


This content processor can be used to programatically create XHTML/XML documents. One could, for example, use it to easily build RSS or ATOM feeds without worrying about unclosed elements and the such.

This extension can only be used if the builder library is installed. The preferred way to do this is via Rubygems:

$ gem install builder


When using this processor, the content needs to be valid Ruby code since the builder library is used that way. The builder object is provided by the xml object which is an instance of the Builder::XmlMarkup class (see the reference for more information).

Once the content is processed, it is replaced by the result of! which returns the generated XML document.

The Webgen::Context object is available, as usual, through the context object.


Generating XHTML

Following is an example page file that uses this processor as the sole content processor in its pipeline to generate some HTML elements:

xml.h1("This a h1 header", :id => 'myid')

xml.p do |p|
  p.text! "You can just write "
  p.b "your"
  p.text! "paragraphs here and"
  p.a("link", :href => "")
  p.text! "them below. This is also a"
  p.i "nice"
  p.text! "format!"

xml.blockquote(:class => 'information') do |bq|
  bq.text! "Citations are easy too."
  bq.text! "Really. And you can assign them attributes."

xml.ul do |ul| "Lists" "aren't" "difficult" "either."

The output would look like this:

<h1 id="myid">This a h1 header</h1>
You can just write   <b>your</b>
paragraphs here and  <a href="">link</a>
them below. This is also a  <i>nice</i>
<blockquote class="information">
Citations are easy too.Really. And you can assign them attributes.</blockquote>

Generating XML

Following is another page file that is now used to generate a custom XML document:

dest_path: '<parent><basename>(-<version>)(.<lang>).xml'
cn: <basename>(-<version>).xml
title: Person Object
template: ~
--- pipeline:builder
xml.persons(:path => context.node.alcn) do |p|
  p.person do |b|
  p.person do |b|
    b.firstname('Other first')
    b.lastname('Other last')

The above page file will produce the following destination file (the alcn in the path attribute would be different of course):

<persons path="/documentation/reference/extensions/content_processor/builder.en.html">
    <firstname>Other first</firstname>
    <lastname>Other last</lastname>