I've been working on a piece of software where I need to generate a custom XML file to send back to a client application. The current solutions on Ruby/Rails world for generating XML files are slow, at best. Using builder or event Nokogiri, while have a nice syntax and are maintainable solutions, they consume too much time and processing.
I definetly could go to ERB, which provides a good speed at the expense of building the whole XML by hand.
HAML is a great tool, have a nice and straight-forward syntax and is fairly fast. But I'm struggling to build pure XML files using it. Which makes me wonder, is it possible at all?
Does any one have some pointers to some code or docs showing how to do this, build a full, valid XML from HAML?
I've not used HAML, but if you can't make it work another option is Builder.
Haml can produce XML just as easily as HTML (I've used it for FBML and XHTML). What problems are you having?
what about creating the xml header, e.g. <?xml version="1.0" encoding="UTF-8"?> ?
It should be possible. After all you can create plain old XML with Notepad.
This demonstrates some things that could use useful for xml documents:
Output:
Look at the Haml::Helpers link on the haml reference for more methods like
haml_tag
.If you want to use double-quotes for attributes,
See: https://stackoverflow.com/a/967065/498594
Or outside of rails use:
run it through haml
open the file in a browser
The HAML reference talks about html tags and gives some examples. HAML reference