Here is a procedure that I used to import XML files into access into access
2002.
Careful with line wraps.
'--------- START CODE -----------------
Private Sub XML_Import(strXMLFile As String, strTable As String)
On Error GoTo Proc_Error
'AUTHOR: Jose Hernandez (
[email protected])
'PURPOSE: Import XML files, specifically Microsoft Baseline Security
Analyzer files.
'COMMENTS: You need to create the table before importing the XML file.
'RERERENCES: Microsoft XML, v3.0 and Microsoft ActiveX Data Objects x.x
Library
'MBSA Scans: %userprofile%\SecurityScans
'MBSA Folder: %ProgramFiles%\Microsoft Baseline Security Analyzer
Dim oXMLDoc As MSXML2.DOMDocument30
Dim oRootElem As MSXML2.IXMLDOMElement
Dim oNodeList As MSXML2.IXMLDOMNodeList
Dim oNode As MSXML2.IXMLDOMNode
Dim oAttrib As MSXML2.IXMLDOMAttribute
Dim oScansRS As ADODB.Recordset
Dim strXSLFile As String
Set oXMLDoc = New MSXML2.DOMDocument30
oXMLDoc.async = False
'Open the ADO xml document
If oXMLDoc.Load(strXMLFile) = False Then GoTo Proc_Exit
Set oScansRS = New ADODB.Recordset
oScansRS.Open strTable, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
'Set oNode = oXMLDoc.selectSingleNode("Reports")
Set oNode = oXMLDoc.firstChild
Set oRootElem = oXMLDoc.documentElement
Set oNodeList = oRootElem.childNodes
For Each oNode In oNodeList
'Debug.Print oNode.xml
'Debug.Print oNode.Attributes.Length
'Debug.Print oNode.Attributes.Item(2).nodeValue
If oNode.Attributes.Length = 0 Then GoTo NextNode
oScansRS.AddNew
For Each oAttrib In oNode.Attributes
'Debug.Print oAttrib.Name & " --> " & oAttrib.Value
oScansRS.Fields(oAttrib.Name).Value = oAttrib.nodeValue
Next oAttrib
oScansRS.Fields("XMLFile").Value = Left(Dir(strXMLFile), InStr(1,
Dir(strXMLFile), ".") - 1)
oScansRS.Fields("NodeText").Value = oNode.Text
oScansRS.Update
NextNode:
Next oNode
Proc_Exit:
If Not oXMLDoc Is Nothing Then Set oXMLDoc = Nothing
If Not oRootElem Is Nothing Then Set oRootElem = Nothing
If Not oNodeList Is Nothing Then Set oNodeList = Nothing
If Not oNode Is Nothing Then Set oNode = Nothing
If Not oAttrib Is Nothing Then Set oAttrib = Nothing
If Not oScansRS Is Nothing Then Set oScansRS = Nothing
'MsgBox "Import Finished..."
Exit Sub
Proc_Error:
MsgBox Err.Description
Resume Proc_Exit
End Sub
'--------- END CODE -----------------
HTH
Jose