Database to xml for data migration

C

Cameron Senior

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!
 
M

Mark T

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
 
C

cs ss

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.
 
R

Robert Klemme

2007/12/10 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top