Ever read RDocs Builder? github.com
Okay, see if I can help a bit. Here is a very far-fetched example.
require 'builder'
@received_data = {:books => [{ :author => "John Doe", :title => "Doeisms" }, { :author => "Jane Doe", :title => "Doeisms II" }]}
@output = ""
xml = Builder::XmlMarkup.new(:target => @output, :indent => 1)
xml.instruct!
xml.books do
@received_data[:books].each do |book|
xml.book do
xml.title book[:title]
xml.author book[:author]
end
end
end
The @output object will contain the xml markup:
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<title>Doeisms</title>
<author>John Doe</author>
</book>
<book>
<title>Doeisms II</title>
<author>Jane Doe</author>
</book>
</books>
To select a specific template, you can pass arguments to your program for this solution.
In any case, I prefer to use libxml-ruby to parse and create XML documents, but that is a matter of taste.
source
share