XML Import -
01-16-2006
, 02:43 AM
Hi All,
I am trying to import some data from various XML files and I seem to getting
a little problem, I have managed to get the files to import by editing the
XML code, but as there are a large amount of files in the directory I dont
want to edit them all.
My XML file looks like :-
<?xml version="1.0"?>
<Ins xmlns:xsd="http://www....com"
xmlns:xsi="http://www.....com">
<Ins>
<InsType>Housel</InsType>
<InsName>West Endl</Ins>
<InsNumber>119174</InsNumber>
<InsNumber>280480</InsNumber>
<Date>31/10/2005</Date>
</Ins>
and my ActiveXscript looks like :-
Function Main()
Dim objFSO
Dim objFolder
Dim objFilesColl
Dim iFilesCount
Dim objFile
Dim objXMLDOM
Dim objNodes
Dim objNodeItem
Dim objADORS
Dim objADOCnn
Dim strCurFileName
'Create and initialize (Open) ADO Connection
Set objADOCnn = CreateObject("ADODB.Connection")
objADOCnn.Open
"PROVIDER=SQLOLEDB;SERVER=Server;UID=UID;PWD=passw ord;DATABASE=Database;"
'Create MSXML 4.0 DOM Object and initialize it
Set objXMLDOM = CreateObject("MSXML2.DOMDocument.4.0")
objXMLDOM.async = False
objXMLDOM.validateOnParse = False
'Get a list of files in the specified directory
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFilesPath)
Set objFilesColl = objFolder.Files
'Load each file in MSXML DOM and use ADO to insert data into the table
For Each objFile in objFilesColl
strCurFileName = strFilesPath & "\" & objFile.Name
'Load the XML file
'No error handling done
objXMLDOM.load strCurFileName
Set objNodes = objXMLDOM.selectNodes("/Ins")
'Create and Open the recordset
Set objADORS = CreateObject("ADODB.Recordset")
objADORS.Open "SELECT * FROM DataSet WHERE 1 = 2", objADOCnn,
adOpenKeyset, adLockOptimistic
'Add records
For Each objNodeItem In objNodes
With objADORS
.AddNew
.fields("InsType") =
objNodeItem.selectSingleNode("InsType").nodeTypedV alue
.fields("InsName") =
objNodeItem.selectSingleNode("InsName").nodeTypedV alue
.fields("InsNumber") =
objNodeItem.selectSingleNode("InsNumber").nodeType dValue
.fields("InsNumber") =
objNodeItem.selectSingleNode("InsNumber").nodeType dValue
.fields("Date") = objNodeItem.selectSingleNode("Date").nodeTypedValu e
' .Update
End With
Next
objADORS.Close
'Message box for debugging purposes
'MsgBox "Copied data from " & strCurFileName & " into the database"
Next
objADOCnn.Close
Set objADORS = Nothing
Set objADOCnn = Nothing
Set objXMLDOM = Nothing
Set objFSO = Nothing
Main = DTSTaskExecResult_Success
End Function
What I need to do is remove the line :-
<?xml version="1.0"?>
<Ins xmlns:xsd="http://www....com"
xmlns:xsi="http://www.....com">
But this is in every file and I dont wish to manually remove it, is there a
way I cn get the script just to ignore this line.
Thanks PD |