Benefits of using XML builder vs templating language like ERB

rubyxml

I'm doing a lot of work with XML, our legacy XML generators use the ruby template language ERB to create the XML files. I've been experimenting with Nokogiri and the builder model of creating XML, but I seem to be able to accomplish everything I want using both methods. So, what should I be taking into account when choosing one common method going forward? What are the benefits of using a builder method to construct the XML vs a template language?

One that I can think of is the builder method(nokogiri) provides methods for do much more than creating the file, such as searching and rearranging, etc. So if I use the builder method I can have a common tool for doing all xml related tasks.

Best Answer

ERb is not an XML templating system. It is a plain text templating system. It doesn't know anything about XML, therefore it cannot guarantee anything about the generated XML code.

<blody>
  <%= 2 + 2 %>
</BoDY>

is perfectly valid ERb but of course not valid XML. This cannot happen with Builder:

xml.body {
  2 + 2
}