Every Friday I have to import a couple (sometimes more than 300) of XML files into 2 tables.
The structure of one of the tables, R000000
, looks like this:
R00000010 | R00000020 | R00000030 | R00000040 | R00000050 | R00000060
---------- ------------ ---------- ----------- ----------- ----------
R000000 | I | 0002 | 1 | 2 | 0026
R000000 | I | 0003 | 1 | 2 | 0025
R000000 | I | 0004 | 1 | 2 | 0021
R000000 | I | 0006 | 1 | 2 | 0023
R000000 | I | 0001 | 1 | 2 | 0022
^
Each row corresponds to an XML file.
The structure doesn't change, only the data (in this case I've placed some random ones for e.g).
The XML files look like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ns0:P4131 xmlns:ns0="http://switching/xi">
<R000000>
<R00000010>R000000</R00000010>
<R00000020>I</R00000020>
<R00000030>0002</R00000030>
<R00000040>1</R00000040>
<R00000050>0026</R00000050>
<R00000060>2</R00000060>
</R000000>
</ns0:P4131>
What is the best way to do this? I'm currently doing this in Access.
Best Answer
Give something like the below a try...
You'll obviously need to plug in your variables for your environment, check the data types (may need to add logic to keep leading zeros?), change from the final temp tables to your regular table(s), etc.
Works fine for me for import from XML files to temp tables without deleting the files afterwards but adding logic to delete files from the UNC path shouldn't be too difficult with another xp_cmdshell command.