Generating XML for a model

Hi yet again!

I’m currently using an erb template to generate XML for a model (say
/persons.xml), because I need custom tags added to the XML I have to
generate it from zero.

I tried using person.to_xml but that returns a whole XML document.

Is there an easier way to insert custom values in a model’s XML
generation? I could redefine the to_xml method but it’d be the same work
of having to include all the other values.

Could I define kind of like a virtual column for the model that gets
picked up by to_xml?

Thanks!

  • Ivan V.

On 26 Jun 2008, at 17:46, Ivan V. wrote:

generation? I could redefine the to_xml method but it’d be the same
work
of having to include all the other values.

Could I define kind of like a virtual column for the model that gets
picked up by to_xml?

yes. See the :only, :except and :methods options to to_xml, or the
block form of to_xml

Fred

Frederick C. wrote:

On 26 Jun 2008, at 17:46, Ivan V. wrote:

generation? I could redefine the to_xml method but it’d be the same
work
of having to include all the other values.

Could I define kind of like a virtual column for the model that gets
picked up by to_xml?

yes. See the :only, :except and :methods options to to_xml, or the
block form of to_xml

Fred

Duh! I should’ve look into the to_xml documentation.

Thanks a lot.

Ivan V.