I’ve published the gem “clifton_lib”, which is intended to be a library of useful things that I’ve built and frequently use myself for Ruby / Rails projects. The functionality I’ve implemented first in this library is a very prototype XML serializer.
In version 0.0.1, I’ve implemented several XML helper classes, similar to .NET’s XmlDocument, to facilitate the creation and serialization of XML. In this version, the support is bare bones but sufficient for what I need done.
Why do this?
All the implementations for XML support that I’ve seen in Ruby utilize the “method missing” feature, so that markup is written in a DSL manner. For example:
doc.product = ‘Apples’
will yield something like:
I have several issues with this:
1. It isn’t object oriented.
2. It assumes you know the element and attribute names, which isn’t convenient when generating XML dynamically from other data sources
3. It leverages “method missing”, which affects performance and creates an internal DSL which isn’t necessary.
4. Frequently, the parameters are passed as hashes, which I find particularly evil in Ruby as they don’t document what the valid parameter-hashes are via function parameters.
Instead, I want to base XML document generation (and eventually parsing) on Microsoft’s implementation of the XmlDocument class in .NET:
1. Is a decent object-oriented solution for creating XML documents
2. Inherently supports dynamic XML generation
3. Isn’t DSL-ish.
Git repository is here: https://github.com/cliftonm/clifton_lib