views:

115

answers:

2

I am implementing an application that manipulate XML documents using Ruby on Rails. I want to have models that encapsulate all the logic and then convert them to corresponding XML document when save. Although I do not need database persistence for my models, I want my models to have validation mechanism like ActiveRecord's. Also, for converting between XML and Ruby objects, an XML mapping library is preferred to make things easier.

Although there are quite a few solutions which allow using ActiveRecord without table, it seems to me the XML mapping libraries (e.g. ROXML, XML Mapping) do not seem to play well with ActiveRecord'S fields. In other words, it does not look like that they can be used together due to the conflict it their syntax.

Therefore, I would like to know what are the preferred solution in this case. The solution which allow the use of an XML binding library with tableless models with validation functionality.

For example, one solution is to have two separate models. One is tableless ActiveRecord and the other is plain Ruby objects with xml binding (like what is described in this post). The ActiveRecord models are for validation. To convert them to XML, it will need to be copies to XML binding models first. Although this solution does work, it is not elegant.

A: 

You are saying that you don't need "database persistence", but then you say that you want to save them to an XML file, and read them from it. So you need persistence - on a file. The difference between that and "database persistence" is only linguistic, since we have SQLite, which stores the whole database on a file.

What you want to do could be done by implementing your own adapter. It would not be complicated, but it would take some time.

egarcia
The application manipulates XML documents but we are not saving them. We send/retrieve the documents to/from another web service. We do not need database persistence in our application.
ejel
A: 

I might made the question looks more complicated that it actually is. Essentially what I wanted are subset of ActiveRecord features (validations, create object from hash) and XML binding. In this case, it is probably better to use standard Ruby objects with libraries that provide comparable functionality to ActiveRecord. For validation, validatable is the right fit. Creating object from hash could also be easily implemented.

In summary, Ruby class + ROXML + validatable gem + custom hash-to-object implementation is the way to go for me.

ejel