Namespaced model valid #to_xml support in ActiveRecord, ActiveSupport and ActiveResource


Attached are links to two patches I submitted via the RoR Trac system
a week or so ago:

I refrained from creating a new Trac ticket for ARes, which will be
affected if both of these patches are accepted by Core.

There are a couple of workarounds for this issue, but it would be nice
for AR, AS and ARes to output valid XML and resolve to namespaced
models correctly from XML respectively. Currently #to_xml on
ActiveRecord::Base and Array creates invalid XML output for namespaced

For one of the workarounds (which unfortunately seems to break RSpec
partial mocks of models) see one of my blog postings at:

Comments are appreciated and I am open to creating a RubyGem or Rails
Plugin to fix this issue if it seems that the Core team do not want to
fix this in Rails any time soon.


An XML namespace has to be declared to be valid xml, so the patches
submitted seem to leave us in the same situation where .to_xml will
produce invalid xml.

So given Module::Model, the only options I can think of are
<module_model> or <model>? Which is better or worse for your
particular situation?

what about '<module-model>' since '-' cannot possible be part of a ruby class/module name? it allows for



That sounds like a reasonable option. Perhaps something else worth
considering is that overriding the root element for a given model
class is a little hard. Perhaps that's a sign we should be refactoring
the serialization a little?

Refactoring serialization +1

I'm also looking at a refactoring that will make it easy to have the
same flexibility in to_json as in to_xml. I probably won't get to it
for a week or two at this rate, but if someone beats me to it I won't
mind too much...