[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Database to xml for data migration

Cameron Senior

12/10/2007 1:58:00 AM

Hi Everyone,

I have searched google for answers and have gone down a few paths of
investigation.... But being a newbie I am rapidly getting confused and
this should essentially be a very simple task.

What I need is some advice on the best way to go about this problem.

We are needing to generate XML documents for a migration into a new
system from an existing database.

I looked into the ruby builder library, but couldn't see too many
examples outside of rails to build the XML up from a template. I know I
can put together a rails app to use an rxml template etc, but going down
that path seems to much effort for this....

I have a template of the xml I need to upload, what I need is to
populate that template for each db record. What is the simplest, best
ruby way to export from the db into xml?

Thanks for your help!
--
Posted via http://www.ruby-....

3 Answers

Mark T

12/10/2007 2:52:00 AM

0

require "rexml/document" ;include REXML

@Skeleton = <<EOF
<anItem desc=""></anItem >
EOF

someItems= REXML::Document.new(@Skeleton)
# Then you could add an/some elements:
# Iterate here
someItems.elements['//anItem'].text = "someThing"


@drTransactionFile = File.open( "someXML.xml", "w")
@drTransactionFile.write("<topLevel >" << someItems.to_s <<
"</topLevel >"); @drTransactionFile.close

Not necessarily fast, maybe simple, doubtfully best.

MarkT

Cameron Senior

12/10/2007 6:25:00 AM

0

Great - thanks for the responses!

I had mostly discounted the rails option but it seems to be the best way
to control the actual output, as there is a bit of processing that needs
to be done on the data.

I just wanted to make sure I wasn't missing the easy way to do this
rather than wrap a framework like rails around a simple db export ruby
script!

thanks again.

--
Posted via http://www.ruby-....

Robert Klemme

12/10/2007 10:10:00 AM

0

2007/12/10, cs ss <cs.subscribe@gmail.com>:
> Great - thanks for the responses!
>
> I had mostly discounted the rails option but it seems to be the best way
> to control the actual output, as there is a bit of processing that needs
> to be done on the data.
>
> I just wanted to make sure I wasn't missing the easy way to do this
> rather than wrap a framework like rails around a simple db export ruby
> script!

Well, if it is just a single and static template you could even use
string interpolation to do the job. Certainly faster than REXML but
YMMV.

Kind regards

robert


--
use.inject do |as, often| as.you_can - without end