Import XML Data into SQL tables

  • Hello,

    I have about 6000 XML files need to import data to SQL tables. The data is not in specific fromat. End users filled Infopath forms and saved as XML document. Now i need to find out those fields and create new tables the import data.

    I tried using SSIS but when i locate XML file in XML source it says "Xml Source adaptor does'nt support mixed content model on complex types". I think data more comples for SSIS to handle. But i cant do anything with data.

    Is there any other option to import XML data like Queries or stored procs in SSMS. I heared that we can do in XQuery, but not sure.

    please reply me if anyone get idea about this..

    Thanks in advance!

    Kumar

  • Your best best is bulk-import the files into an XML datatype column, and then parse them out with XQuery.

    If you aren't familiar with querying XML data, this will not be easy. You may want to talk to management about bringing in a contractor to do the job for you.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • im no XML expert but, i use this command to import xml files in to my database, I created a SP using the dynamic SQL so i can pass it a location and file name.

    insert into #xml_table SELECT * FROM OPENROWSET(BULK N'c:\temp\filename.xml', SINGLE_CLOB) AS xmldata

    set @XML_exec ='insert into #xml_table SELECT * FROM OPENROWSET(BULK N'+char(39)+@file+char(39)+', SINGLE_CLOB) AS xmldata'

    Exec (@XML_exec)

    ***The first step is always the hardest *******

  • You probably will want to find out where the mixed content actually is. Mixed content tends to be problematic no matter what in just about any xml handling, since it sets up some room for ambiguous answers on how to return nodes with mixed content.

    As a matter of background, XML mixed content is where you have BOTH text AND children nodes in a given element. So you're looking for something that might look like:

    <root>

    <mixedcontentnode>

    The <operator value="Cow"/> Jumped over the <actionObject val="moon"/>.

    </mixedcontentnode>

    </root>

    In short you will find a lot of xquery engines having a rough time figuring out what to return with they are asked for the text() out of the mixedcontentnode above.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Thank you all for reply!

    thing is that i dont have Bulk Insert permissions. Can we do it by writing C# code using Script task in SSIS?

    Kumar

  • Probably. I'm not as familiar with script tasks in SSIS as I probably should be. But why not get your SSIS package assigned a credential with bulk-import permissions? That would be the easiest solution.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Matt Miller,

    Thanks a lot, its solved the issue which I am struggling for last 2 days!!

  • Hi

    So what was your solution here? We're having a similar problem that we are trying to resolve.

    Thanks,

    Patrick

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply