Question

  Asked: Feb 3 2008   11:11 AM GMT
  Asked by: Adysann


SQL SERVER 2005 XML LOAD


XML, SQL Server 2005

Hi EVeryone,

Having a text file (in which resides the xml data and the xml schema definition),i have to create the afilliate tables to that XML(+XSD).The problem is the XSD is variable , and can not be hardcoded, i mean that XSD could vary from file to file...
Is there a way to create automatically the tables and load them with data from the xml?

Greets,
Adrian

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



You can use BULK INSERT to load the entire XML file into a single field of a single record of a temp table. Then use OPENXML to query for the XML and XSD (I'm pretty sure you can query for the inline XSD in this mannor, if you you can probably figure it out by looping through the data structor directly). Use this information to dynamically create the CREATE TABLE scripts and then execute the scripts, then use dynamic SQL to load the data from the OPENXML into the new tables.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development and SQL Server.

Looking for relevant Development Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Mrdenny  |   Feb 4 2008  7:14AM GMT

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.