Import XML file into SQL 2000

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
SynsorITAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Anthony PerkinsConnect With a Mentor Commented:
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
 
Anthony PerkinsCommented:
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
 
SynsorITAuthor Commented:
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
 
Anthony PerkinsCommented:
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
 
SynsorITAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.