Rails magic for MySQL -> XML file -> MySQL and back again?


#1

Greetings!

My little app collects data from the user, persists it in about a dozen
tables during the session, writes out / saves an XML file that’s
downloaded to the user’s PC when they’re done, then clears the db of all
data entered, and deletes the XML file from the server.

Now I need to allow the user to upload the same XML file they created
earlier and put it back in the database so that, using the same app they
used to create it, they can edit / update it and save / download it to
their PC again.

Can somebody point me in the right direction here, please? What’s the
Rails way of approaching this? Is there some way to ‘bind’ (don’t know
if that’s the right word here) the XML file to the db? Some Rails
magic, maybe?

Thanks in advance,
Bill


#2

Bill W. wrote:

Greetings!

My little app collects data from the user, persists it in about a dozen
tables during the session, writes out / saves an XML file that’s
downloaded to the user’s PC when they’re done, then clears the db of all
data entered, and deletes the XML file from the server.

Now I need to allow the user to upload the same XML file they created
earlier and put it back in the database so that, using the same app they
used to create it, they can edit / update it and save / download it to
their PC again.

Can somebody point me in the right direction here, please? What’s the
Rails way of approaching this? Is there some way to ‘bind’ (don’t know
if that’s the right word here) the XML file to the db? Some Rails
magic, maybe?

Thanks in advance,
Bill

Bill,

Not to sure of Rails magic but you could use an xslt stylesheet to
transformt he xml into an sql insert query then run that to populate the
db.

Hope this helps
Danny


#3

Hi Danny,

Danny Malone wrote:

their PC again.

Can somebody point me in the right direction here, please? What’s the
Rails way of approaching this? Is there some way to ‘bind’ (don’t know
if that’s the right word here) the XML file to the db? Some Rails
magic, maybe?

Not to sure of Rails magic but you could use an xslt stylesheet to
transformt he xml into an sql insert query then run that to populate the
db.

Thanks for the suggestion! Any example / tutorial links you could point
me
to?

Best regards,
Bill


#4

Bill,

this thread seems to have stopped, but I wonder how far you got with
your
application. I have been googling for some time now and the
information on
handling xml files in rails is sparse. (To be fair, rails is aimed at
database apps.) .

I wanted to do something very much along the same lines, although not
quite so complex as your requirement. After entering data into tables,
I
want to save the summary (an order with customer detailsm and order
information) in fairly simple xml format on the (intanet) server where
it
can be separately accessed as required. Then I want to allow the user
to
reload the xml file at a later date, be able to modify it and save it
back.

If you had any helpful examples, I would be most grateful. I am not
an
xml or xslt expert, but I need to grapple with this. I have done some
xml
file handling/editing in php, but managing something similar from rails
does
not seem to be quite so obvious.

Once I have my xml file, I thought I could build an xslt to allow it to
be
later viewed in a browser. And I am also thinking towards providing the
ability to import it into OpenOffice for off line editing.

I would be grateful for any useful links or advice you might be able to
offer.

Tony

Bill W. wrote:

Not to sure of Rails magic but you could use an xslt stylesheet to


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


View this message in context:
http://www.nabble.com/Rails-magic-for-MySQL-->-XML-file-->-MySQL-and-back-again----tf1522315.html#a5713999
Sent from the RubyOnRails Users forum at Nabble.com.


#5

Hey Tony,
Sorry to jump into your thread un-invited, but, getting information
from a Rails application, loading ‘into’ it an xml document from
‘intranet’ … call me crazy (ishmael) but, doesn’t this scream XMLRPC ?
XMLRPC methods should be fairly easy to knock up to export a record
and/or update from the database in conjunction with AR. Jst a thought,
feel free to ignore it as you feel appropiate :slight_smile:

Regards
Stef

#6

Hi Tony,

Tony Martin wrote:

I wonder how far you got with your application. I have
been googling for some time now and the information on
handling xml files in rails is sparse.

I’m using Builder::XMLmarkup to output the XML files and REXML to read
them
back in. Both are slam-dunk simple and both are included in the
standard
distro. The documentation for Builder is at
http://api.rubyonrails.org/.
The documentation for REXML is at
http://www.germane-software.com/software/rexml/.

If you had any helpful examples, I would be most grateful.

Take a look at the above and let me know if you have any specific
questions.
Be glad to try.

Once I have my xml file, I thought I could build an xslt to
allow it to be later viewed in a browser.

I’d be interested in anything you come up with re: XSLT. I’m not using
it
at this point, but may have a need on the horizon. I haven’t used it
yet,
and it’s not included in the standard distro (yet, I hope), but
http://raa.ruby-lang.org/project/ruby-xslt/ is probably where I’ll
start if
I end up going down that path.

hth,
Bill


#7

Steff, thanks for your suggestion. however, I am wanting to save and
reload
xml files directly from the file system, so will be doing fileio not
talking
to another app. My aim is to provide an xml format that can be accessed
directly from PCs on the network and edited without going through the
web
server.

I am however making some progress. this is my first development in
both
rails and Ruby so I am feeling my way here… I am building a
replacement/conversion of an existing MS Access database, and trying to
emulate fairly closely the original database functionality an view and I
am
pleased to say that Rails is generally excelling iteslf.

On the XML side, I notice from Bill’s earlier posts that there is an
issue
if I use builder to create and render an rxml view because after the
render, i will not be able to redirect to a new page. What I am
proposing
to do is use Builder to directly create an XML string within the
controller,
save it to a file and then redirect to a page that will display the xml
from
the file and allow for some editing. If that sounds bizarre please let
me
know.

If anyone has any pointers to xml file i/o and parsing I would be
grateful.

Thanks
Tony

View this message in context:
http://www.nabble.com/Rails-magic-for-MySQL-->-XML-file-->-MySQL-and-back-again----tf1522315.html#a5730478
Sent from the RubyOnRails Users forum at Nabble.com.


#8

Stef,

thanks for the pointers. Webdav is something I hadnt really
encountered,
but yes that is the genereal direction. since I am only looking to
generate
some very simple and standard file formats, what I am trying to achieve
is
much simpler. The files will also be very small.

I have found that using Builder, creating the xml into a Builder object
is
really simple, and it should be possible to write this to a file as a
string.

I have seen reference to Hash.create_from_xml, but cannot get rails to
recognize it. I have also had a quick look at XmlSimple and xml_in may
be
all I need, although it seems to fail if the xml tags do not include
attributes. i have had a quick look at LibXML, and it should provide
what
I need to read the file so I will pursue that and let you know how it
goes.

Thanks again.
Tony

View this message in context:
http://www.nabble.com/Rails-magic-for-MySQL-->-XML-file-->-MySQL-and-back-again----tf1522315.html#a5753166
Sent from the RubyOnRails Users forum at Nabble.com.


#9

Hey Tony,
Well, if your wanting to read and write xml files from the file
system, your best bet is -definitely- libxml. Unlike certain other
products that I could mention, the documentation is really rather good,
and gives working examples of how to do this. Url is
http://libxml.rubyforge.org/doc/.

 Perhaps I am missing something, and thats always possible, but,

unless your wanting to write an xml editor that fits -inside- the web
browser, you have two ways that I see; xml-rpc (think WebDav sort of :wink:
or libxml and command line.

Regards
Stef