Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

OpenXML soultuion clarification

Posted on 2008-10-15
12
Medium Priority
?
458 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

916 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