Best way to interface with XML databases

Hi,

I am trying to interface Rails with an XML database (Berkeley DB XML).

The sort of features that I want to implement are:
Essential:
  - load a complete XML document in the database into a tree of objects
  - save a tree of objects into an XML document in the database
  - introspect an XML schema (XSD) to determine the attributes that model classes should have (similar in concept to the way ActiveRecord determines the attributes of model classes by querying a relational database's data dictionary)
  - marshalling HTTP POST from forms into (trees of) model objects

Desirable:
  - load part of an XML document into a tree of objects
  - lazy loading of associated XML nodes
  - partial updates of XML documents using XQuery Update

I'd appreciate any thoughts on the best general approach. At the moment I am considering two approaches:
1) Write an ActiveRecord connection adapter and either make the adapter parse SQL and convert it to XQuery (which I'm not too keen on) or monkey patch the parts of ActiveRecord that use SQL.
2) Write a new framework from scratch that borrows ideas from ActiveRecord.

I've read previous discussions on non-SQL databases and ActiveRecord; am I right in thinking that patches to refactor ActiveRecord to separate out all of the SQL stuff would be unlikely to be accepted?

Any thoughts or advice would be very welcome!

Thanks,

Francis

The current thought is to refactor the model aspects from ActiveRecord
(validations, callbacks, etc) into ActiveModel, and use that for any
other ORM style libraries you want to write. Then, you can just write
some ActiveBerkeley library using ActiveModel and mimicking
ActiveRecord's API where possible.