Solved

Import XML file into SQL 2000

Posted on 2010-09-13
5
682 Views
Last Modified: 2012-05-10
Greetings,

I searched the tried to find an existing answer that could help but due to my limited knowledge of importing xml could not find a solution that would work.

Our engineers use solidworks which when a part is "approved" will generate an XML file with information regarding the part.

What i am looking for is either a sql procedure or code for visual studio that will take the values in the XML file and import them into a temporary table in SQL 2000.

The included XML file is an example of what is exported by Solidworks, at this point we are only concerned with the part itself and not the rest of the XML which is the BOM for the part.  Everything under <references> is the bom which we do not need at this point.

I only need the following attributes from the first part (part itself) to be added as columns in the SQL temp table.
FDESCRIPT
FSTDMEMO
FREV
Vendor
FPRODCL
FPARTNO
FGROUP
Stock Usage
Stock Description
Stock Number
FSOURCE
FMEASURE



Please let me know if i missed any important information and thank you all very much!!!



TESTASM1-X.XML
0
Comment
Question by:SynsorIT
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 33668624
You would use something like this:
DECLARE @Xml varchar(8000)



SET @Xml = '

<xml>

	<transactions>

		<transaction date="1284414935" type="wf_export_document_attributes" vaultname="Test">

			<document aliasset="ERP" id="TESTASM1" idattribute="Part Number" idcfgname="Default" pdmweid="9894">

				<configuration name="Default" quantity="1">

					<attribute name="FDESCRIPT" value="XXXASM1" /> 

					<attribute name="FSTDMEMO" value="" /> 

					<attribute name="FREV" value="X" /> 

					<attribute name="Vendor" value="" /> 

					<attribute name="FPRODCL" value="" /> 

					<attribute name="FPARTNO" value="TESTASM1" /> 

					<attribute name="FGROUP" value="" /> 

					<attribute name="Stock Usage" value="" /> 

					<attribute name="Stock Description" value="" /> 

					<attribute name="Stock Number" value="" /> 

					<attribute name="FSOURCE" value="Make to Order" /> 

					<attribute name="FMEASURE" value="EA" /> 

					<attribute name="Configuration" value="Default" /> 

					<attribute name="Reference Count (BOM Quantity disregarded)" value="1" /> 

					<references>

						<document aliasset="ERP" id="testPart1" idattribute="Part Number" idcfgname="Default" pdmweid="9886">

							<configuration name="Default" quantity="1">

								<attribute name="FDESCRIPT" value="XXXPART1" /> 

								<attribute name="FSTDMEMO" value="" /> 

								<attribute name="FREV" value="X" /> 

								<attribute name="Vendor" value="" /> 

								<attribute name="FPRODCL" value="" /> 

								<attribute name="FPARTNO" value="testPart1" /> 

								<attribute name="FGROUP" value="" /> 

								<attribute name="Stock Usage" value="-" /> 

								<attribute name="Stock Description" value="" /> 

								<attribute name="Stock Number" value="" /> 

								<attribute name="FSOURCE" value="Make to Order" /> 

								<attribute name="FMEASURE" value="EA" /> 

								<attribute name="Configuration" value="Default" /> 

								<attribute name="Reference Count (BOM Quantity disregarded)" value="1" /> 

		  					</configuration>

  						</document>

 						<document aliasset="ERP" id="testPart2" idattribute="Part Number" idcfgname="Default" pdmweid="9887">

 							<configuration name="Default" quantity="1">

								<attribute name="FDESCRIPT" value="XXXPART2" /> 

								<attribute name="FSTDMEMO" value="" /> 

								<attribute name="FREV" value="X" /> 

								<attribute name="Vendor" value="" /> 

								<attribute name="FPRODCL" value="" /> 

								<attribute name="FPARTNO" value="testPart2" /> 

								<attribute name="FGROUP" value="" /> 

								<attribute name="Stock Usage" value="-" /> 

								<attribute name="Stock Description" value="" /> 

								<attribute name="Stock Number" value="" /> 

								<attribute name="FSOURCE" value="Make to Order" /> 

								<attribute name="FMEASURE" value="EA" /> 

								<attribute name="Configuration" value="Default" /> 

								<attribute name="Reference Count (BOM Quantity disregarded)" value="1" /> 

  							</configuration>

  						</document>

  					</references>

  				</configuration>

  			</document>

  		</transaction>

  	</transactions>

</xml>'



DECLARE @Doc integer



EXEC sp_xml_preparedocument @Doc OUTPUT, @Xml

-- INSERT TemporaryTable (FDESCRIPT, FSTDMEMO, FREV, Vendor, FPRODCL, FPARTNO, FGROUP, 

--                  StockUsage, StockDescription, StockNumber, FSOURCE, FMEASURE)

SELECT	FDESCRIPT,

	FSTDMEMO,

	FREV,

	Vendor,

	FPRODCL,

	FPARTNO,

	FGROUP,

	StockUsage,

	StockDescription,

	StockNumber,

	FSOURCE,

	FMEASURE

FROM	OPENXML (@Doc, 'xml/transactions/transaction/document/configuration', 1) WITH (

		FDESCRIPT varchar(20) 'attribute[@name="FDESCRIPT"]/@value',

		FSTDMEMO varchar(20) 'attribute[@name="FSTDMEMO"]/@value',

		FREV varchar(20) 'attribute[@name="FREV"]/@value',

		Vendor varchar(20) 'attribute[@name="Vendor"]/@value',

		FPRODCL varchar(20) 'attribute[@name="FPRODCL"]/@value',

		FPARTNO varchar(20) 'attribute[@name="FPARTNO"]/@value',

		FGROUP varchar(20) 'attribute[@name="FGROUP"]/@value',

		StockUsage varchar(20) 'attribute[@name="Stock Usage"]/@value',

		StockDescription varchar(20) 'attribute[@name="Stock Description"]/@value',

		StockNumber varchar(20) 'attribute[@name="Stock Number"]/@value',

		FSOURCE varchar(20) 'attribute[@name="FSOURCE"]/@value',

		FMEASURE varchar(20) 'attribute[@name="FMEASURE"]/@value'

		)



EXEC sp_xml_removedocument @Doc

Open in new window

0
 

Author Comment

by:SynsorIT
ID: 33673726
Solidoworks outputs the XML file as "partnumber".xml

Is there a way to modify this code to look at the xml files in a specific folder?

Example;
We have a folder y:/_BOMexport
1000146.xml
1000690.xml
1000710.xml
and so on

There could be hundreds of these a day.  Ideally we would want to read all files in the y:/_BOMexport folder and delete them after reading into sql.

Thank you!!!
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 33674702
For many reasons, but foremost security and performance, you are better off passing the Xml files using a front-end app written in VB or .NET rather then using MS SQL Server to do this.  That is not to say that you cannot do it using something like OPENROWSET() or (God forbid) the sp_OA* funtions, it is just that for your own sanity, don't do that, MS SQL Server was never intended for that purpose and using it as if it was MS Access is a very bad idea.
0
 

Author Comment

by:SynsorIT
ID: 33675058
So would best practice go something like this?

.net
- grab xml file from y:/_bomexport
- pass xml to temporary table in SQL (or should it pass the xml directly into the "item master" table)
- take xml data in SQL temp table and divide into columns and insert into "item master" table
- delete xml file from y:/bomexport
- repeat for all files in y:/bomexport


Thanks for your help, i am very new to this but am learning!!!
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 33678230
I would:
1. Load it with .NET
2. Pass it into SQL Server via a Stored Procedure.
3. Shred the Xml into a variable of type table (as opposed to a temporary table).
4. Validate the results in the variable of type table.
5. If it passes load into your "Item Master" table.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

747 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

10 Experts available now in Live!

Get 1:1 Help Now