XML question

Is there a way you can use RoR to create an .xml file?

Say I had a DB full of info that I wanted to format and have export as
“lorem.xml” inside of a specific directory in my web server?

Then, each time I updated the DB it would re-export the file (delete the
old, save the new?)

Hi Mason,

Bill,

I found how i could generate an .xml file on the fly with .rxml, much
like i can generate an .html file with .rhtml.

While this will create the file I need, it only exists momentarily and
then dissapears leaving me with only a .rxml once the RoR actions are
done. What I would like to do is have the .xml export to a separate
location so that it can be used by another application.

The RoR is there to act as an CRUD for the XML info. I want my client to
be able to add/edit/delete items from its XML file.

Is it possible to set up the .xml file to save in a specified directory
once the .rxml pieces it together into a .xml?

thanks,
mk

Bill W. fat-fingered:

Hi Mason,

Mason K. wrote:

Is there a way you can use RoR to create an .xml file?

There are several options. The choice depends mainly on the complexity
of
what you’re trying to do. Builder and REXML will do 98% of anything
you’d
want to do and they’re both part of the standard distro.

HTH,
Bill

Mason,

Don’t forget that ActiveRecord objects have a .to_xml method that
will output xml. You can then write that out to a file if necessary.

-Anthony

Mason K. wrote:

I found how i could generate an .xml file on the fly
with .rxml, much like i can generate an .html file with
.rhtml.

While this will create the file I need, it only exists
momentarily and then dissapears leaving me with
only a .rxml once the RoR actions are done. What
I would like to do is have the .xml export to a separate
location so that it can be used by another application.

One option, if you’re sure you just want to save what you’re already
rendering, might be to render_to_string and then save that to a .xml
file.
Might be worth a shot, but I wouldn’t be surprised if it didn’t work for
one
reason or another.

The RoR is there to act as an CRUD for the XML info.
I want my client to be able to add/edit/delete items from
its XML file.

To make sure I read this right… you don’t mean you want to edit the
XML
file natively do you? If so, I think that would be pretty far outside
the
sweet-spot for RoR.

If I understand what you mean by "RoR is there to act as… ", then
you’re
probably thinking along the lines of what I’m doing. My RoR app
captures
data from the visitor into MySQL (in my case). When they want to save
the
data they’ve entered, I use Builder to create an XML file from the data
stored in MySQL. If they want to update an existing file, I use REXML to
bring the data stored in the XML file (back) into MySQL, etc… That is
pretty much dead center of the RoR sweet spot wrt XML, IMO.

Is it possible to set up the .xml file to save in a specified
directory once the .rxml pieces it together into a .xml?

Independent of how you get there, you’re going to end up just doing a
routine file save. Nothing magic there.

hth,
Bill