|
| hello,
a while back i wrote a activeX script to import xml files, but i was
unable to figure out error handling. What i want, is while reading the
"nodes" of the xml file, if any error occurs, i want a record inserted into
another table and the import for that file aborted. i have attempted this by
using a on error resume next clause before every read into the node, but it
does not seem to catch the failures. Basically i have 1 or more files that
the last xml closing tag seems to have been forgotten and i want this error
to be reported. any suggestions? below is my code:
'Loop through each file in the folder
For Each fsoFile in fsoFolder.Files
'Check for proper file extension
If LCase(Right(fsoFile.Name,4)) = ".xml" and LCase(Left(FsoFile.Name,5)) =
"stats" Then
'Create the full file name
sFileName = sFolderImport & fsoFile.Name
sShortFileName = fsoFile.Name
'Ensure this file has not already been imported to any of the tables
On Error Resume Next
objXMLDOM.load sFileName
If Err.number <> 0 Then
' File could not be loaded
objADOCon.Execute("INSERT INTO dbo. SpamLogsImportErrors
VALUES ('" &
Now() & "', '" & sFileName & " could not be loaded')")
Else
'Set the object nodes
On Error Resume Next
Set objNodes = objXMLDOM.selectNodes("/EventLog/Event")
If Err.number <> 0 Then
'Nodes could not be found
objADOCon.Execute("INSERT INTO dbo. SpamLogsImportErrors
VALUES ('" &
Now() & "', '" & sFileName & " could not get nodes')")
End if
'Clear event counter
eventNum = 0
'Loop through each event node
For Each objEventNode in objNodes
'Increment the counter
eventNum = eventNum + 1
'Retrieve appropriate data from the node
On Error Resume Next
strDate =
Left(objEventNode.selectSingleNode("@local-time").nodeTypedValue,19)
If Err.number <> 0 Then
' Problem with file
objADOCon.Execute("INSERT INTO dbo. SpamLogsImportErrors
VALUES ('" &
Now() & "', '" & sFileName & " could not get date field (event number: " &
eventNum & "')")
End if
strDate = Replace (strDate, "_", " ")
On Error Resume Next
Next
'Close the recordset
objADORS.Close
End IF
End IF
Next
|
|