I’ve uploaded a small library to Rubyforge that allows you
to markup data using XML tags using direct Ruby assignment
following the example of OpenStruct.
The library supports attributes and simple text elements -
all of which are XML escaped before output. The interface is
designed to be as simple as possible, with the least amount
of syntactic sugar. The general idea is that you mark up your
flat data and output a string containing the markup.
The system works best when you have a small amount of data,
and a large amount of irritating XML structure to impose upon
it. The class came about to allow me to quickly draw up XML
messages to send to the UK Government Gateway. Boy can you
tell that that schema was designed by committee.
I hope that it finds some use somewhere.
Usage
I hope the interface is intuitive. Very simply you use assignment
commands, e.g
I don’t like the reuse of xml inside of each of the blocks. IIRC it is
why I dislike the CGI library. Visually it looks like
everything gets appended right to xml, although thinking twice I know
that the block scope is actually where the xml addition
takes place.
I don’t like the nested braces syntax and my system is not interested
in the XML layout. The straight assignment just seems simpler to me,
and I find it useful when I’m doing assignments throughout a program
rather than in just one place.
Builder is much more powerful. I didn’t need the power, but I needed
the simplicity. Hence why I built XmlStruct. (That and learning a bit
about reflection and meta-programming).
NeilW
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.