dbTalk Databases Forums  

XML Import

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss XML Import in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil
 
Posts: n/a

Default 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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.