Database to xml for data migration

Discussion in 'Ruby' started by Cameron Senior, Dec 10, 2007.

  1. 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-forum.com/.
     
    Cameron Senior, Dec 10, 2007
    #1
    1. Advertisements

  2. Cameron Senior

    Mark T Guest

    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
     
    Mark T, Dec 10, 2007
    #2
    1. Advertisements

  3. Cameron Senior

    cs ss Guest

    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-forum.com/.
     
    cs ss, Dec 10, 2007
    #3
  4. 2007/12/10, 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!


    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
     
    Robert Klemme, Dec 10, 2007
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john doe

    old database migration to java

    john doe, Feb 3, 2004, in forum: Java
    Replies:
    1
    Views:
    365
    Andrew Thompson
    Feb 3, 2004
  2. Harry Zoroc
    Replies:
    1
    Views:
    1,027
    Gregory Vaughan
    Jul 12, 2004
  3. Jerry Jones

    Database migration

    Jerry Jones, Feb 6, 2007, in forum: Ruby
    Replies:
    2
    Views:
    100
    Mike Harris
    Feb 6, 2007
  4. Sholto Douglas
    Replies:
    0
    Views:
    480
    Sholto Douglas
    Jun 6, 2011
  5. Boni Satani
    Replies:
    0
    Views:
    216
    Boni Satani
    Jan 9, 2014
Loading...

Share This Page