SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Import XML Data into SQL tables


Import XML Data into SQL tables

Author
Message
Kumar SQL
Kumar SQL
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 176
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
GSquared
GSquared
SSC Guru
SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)

Group: General Forum Members
Points: 55225 Visits: 9730
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
SGT_squeequal
SGT_squeequal
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1165 Visits: 1118
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 is always the hardestw00t
Matt Miller (4)
Matt Miller (4)
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28205 Visits: 18999
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?
Kumar SQL
Kumar SQL
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 176
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
GSquared
GSquared
SSC Guru
SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)

Group: General Forum Members
Points: 55225 Visits: 9730
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
durga.palepu
durga.palepu
SSC Eights!
SSC Eights! (842 reputation)SSC Eights! (842 reputation)SSC Eights! (842 reputation)SSC Eights! (842 reputation)SSC Eights! (842 reputation)SSC Eights! (842 reputation)SSC Eights! (842 reputation)SSC Eights! (842 reputation)

Group: General Forum Members
Points: 842 Visits: 222
Matt Miller,

Thanks a lot, its solved the issue which I am struggling for last 2 days!!
Pat-427049
Pat-427049
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 80
Hi

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

Thanks,
Patrick
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search