1

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.

1 Answer 1

1

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
}
2
  • IME builders are vastly preferable to templates. Commented Aug 15, 2013 at 19:35
  • so in your opinion we shouldnt use to build html too? erb has better performance than xml builder, its easier to implement russian doll caching and one less DSL to learn..
    – VP.
    Commented May 25, 2018 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.