Skip to main content
September 2, 2010
Question

Getting data from an XML file and pushing it to a database

  • September 2, 2010
  • 1 reply
  • 763 views

I need to create a coldfusion page that grabs an incoming xml file, extract the data and then push it into a database. I have never done anything like this, and have been reading as much as I can find. Can anyone recomend a good resource or give me a hand on how I go about doing this?

The xml file is coming from another page. Basically the source page is a simple text box that an xml file is pasted into and submited. The action page must grab the xml file, pull out the data and funnel it into a table. Then it must query the table and based on the results of the query, push a new xml file back to the user.

<my brain is already hurting>

    This topic has been closed for replies.

    1 reply

    ilssac
    Inspiring
    September 2, 2010

    Is it an incoming file?  Or just in xml string?

    ColdFusion is really, pretty good at working with XML data.  If it is well formed XML and you can execute the xmlParse() function, then you can access the XML with simple dot or array syntax as well as array or structure loops and XML xpath search or XSLT transforamtions.

    With all those options, it is pretty easy to create a routine that will parse through XML data and process it into a database or whatever else you want to do with it.

    This, of course, presumes that you just don't want to feed the database the straight XML.  Since, most modern database management systems, also understand XML and can often work with it directly as well.

    September 2, 2010

    Im not sure if it is a file or a string. I have never worked with xml before, so i am not sure. Here is an examle of what is

    coming through:

    <request last_id="2"account_id="278" />

    <response />

    After I use xmlParse() function, how do I then access the data. THis is very confusing to me.

    Inspiring
    September 2, 2010

    I'd start by looking at the CF documentation related to XML and Ben Forta's books.

    "About XML and ColdFusion" from CF docs:

    http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec133ba-8000.html

    Ben Forta's books

    http://www.forta.com/books/0321679199/

    It would be good to know:

    1. What the workflow is for your task. Can you describe your task in detail and provide samples of the XML and database?

    2. The database you are using and the structure of your tables.

    3. The version of CF you are using.