Solved

OpenXML soultuion clarification

Posted on 2008-10-15
12
431 Views
Last Modified: 2013-11-15
I found a solution I believe to work provided by Hilaire, but I am unsure of how to get the results.   The solution I found is here: http://www.experts-exchange.com/Database/Miscellaneous/Q_21390833.html?sfQueryTermInfo=1+openxml .  I was able to create the stored procedure but when I run that last bit of code to work the magic I get 0 results.  I did change the path to a valid XML file located locally.

I am trying to read a very large XML file in SQL so that I may query it and put certain records in an existing database.
0
Comment
Question by:websuperman
  • 7
  • 5
12 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22725049
Define "VERY LARGE" because he states "This version handles files up to 74000 characters".

That is also 3+ years old and probably written for SQL 2000 so why don't you say what you want to do, and then we can decide if that's right for you.
0
 
LVL 2

Author Comment

by:websuperman
ID: 22725199
Good Point.  I am using SQL 2005  The file is 63,000 KB.  I need to query it against other data sources so that I may extract data from this very large XML file and input it into the database.  It is icecat xml.  My ultimate goal is to get all the product data into a web site.  The information I really need for now is the path, product_ID, Prod_ID and Catid.  I woud like to have and be able to use the product information as well but that seems a bit lofty for me at the moment.  The structure of this file is as follows.  

<?xml version="1.0"?>

<!DOCTYPE ICECAT-interface SYSTEM "http://data.icecat.biz/dtd/files.index.dtd">

<ICECAT-interface>

	<files.index Generated="20081013071404">

		<file path="export/freexml/10.xml" Product_ID="10" Updated="20081007111957" Quality="ICECAT" Supplier_id="1" Prod_ID="C8934A#A2L" Catid="234" On_Market="0"/>

		<file path="export/freexml/1286.xml" Product_ID="1286" Updated="20081007111957" Quality="SUPPLIER" Supplier_id="1" Prod_ID="D9190B" Catid="156" On_Market="0"/>

		<file path="export/freexml/1287.xml" Product_ID="1287" Updated="20081007111957" Quality="SUPPLIER" Supplier_id="1" Prod_ID="D9192B" Catid="156" On_Market="0"/>

		<file path="export/freexml/1288.xml" Product_ID="1288" Updated="20081007111957" Quality="SUPPLIER" Supplier_id="1" Prod_ID="D9194B" Catid="156" On_Market="0"/>

		<file path="export/freexml/1289.xml" Product_ID="1289" Updated="20081007111957" Quality="SUPPLIER" Supplier_id="1" Prod_ID="D9196B" Catid="156" On_Market="0"/>

	</files.index>

</ICECAT-interface>

Open in new window

0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22725293
I can assure you that 63mb is more than 74k characters :)

Due to it's size, you may be better off opening and parsing the xml file in a different language and inserting records into SQL.
0
 
LVL 2

Author Comment

by:websuperman
ID: 22725324
hmmm, not sure where to go from here then.  If I could get the data into SQL I can handle that, trick right now seems to be getting the data accessible for queries.  Any suggestions?
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22725433
create table #XML (MyXML XML null)

insert into #XML(MyXML)
   SELECT * FROM OPENROWSET(BULK N'C:\Text1.xml', SINGLE_BLOB) AS Document

--Do stuff with the XML

drop table #xml
GO
0
 
LVL 2

Author Comment

by:websuperman
ID: 22725784
Tried this without success, probably not following:

create table #XML (MyXML XML null)

insert into #XML(MyXML)
   SELECT * FROM OPENROWSET(BULK N'C:\Text.xml', SINGLE_BLOB) AS Document

Update MyTable SET MyTable.category = #XML.CatID Where MyTable.sku = #XML.Prod_ID

drop table #xml
GO

No Good, :
The multi-part identifier "#XML.Prod_ID" could not be bound.
I tried multiple variations to get away from the error without luck, testing on smaller file.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22726060
I'm working something else up.  But I need to know if you need to filter by a particular <files.index Generated> or if there will always be only one files.index node.

quickly perferably
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22726098
Here you go:
declare @XML XML 

     ,@i int
 

select @XML=convert(xml, bulkcolumn,2) from openrowset(BULK N'c:\temp\test.xml',SINGLE_BLOB) as Document
 

exec sp_xml_preparedocument @i=@i output, @xml=@xml
 

select * from openxml (@i,'/ICECAT-interface/files.index/file')

     with ([path]        nvarchar(max)

          ,Product_ID    int

          ,Prod_ID       nvarchar(max)

          ,Catid         int)
 

exec sp_xml_removedocument @i=@i

Open in new window

0
 
LVL 2

Author Comment

by:websuperman
ID: 22726492
should always be a single <files.index> node
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22727078
Then that (http:#22726098)should work.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22727080
then that (http:#22726098 ) should work.
0
 
LVL 2

Author Closing Comment

by:websuperman
ID: 31506475
Thank you, this works great and meets my needs.  I appreciate the speedy responses.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Save conflict messages on existing documents 15 50
SQL Query with Sum and Detail rows 2 40
SQL Login 17 38
Anyway to make these 2 SQL statements into one? 13 23
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now