I'm trying to import a bunch of .xml files into Access tables. I've created a .xslt file that works fine when I manually run the import in Access. But when I try using VBA code (which I pulled from another post here) to transform the .xml file, the resulting temp.xml file is completely empty. What am I missing?
Public Sub TransformAndImportMultipleXMLs()
Dim strFile As String, strPath As String
Dim xmlDoc As New MSXML2.DOMDocument60
Dim xslDoc As New MSXML2.DOMDocument60
Dim newDoc As New MSXML2.DOMDocument60
strPath = "y:\"
strFile = Dir(strPath & "*.xml")
xslDoc.async = False
xslDoc.validateOnParse = False
xslDoc.resolveExternals = False
xslDoc.Load "C:\JSTAdb\LinkIncidentID.xslt"
While strFile <> ""
' REINITIALIZE DOM OBJECTS
Set xmlDoc = New MSXML2.DOMDocument60
Set newDoc = New MSXML2.DOMDocument60
' LOAD XML SOURCE
xmlDoc.Load strPath & strFile
' TRANSFORM SOURCE
xmlDoc.transformNodeToObject xslDoc, newDoc
newDoc.Save "C:\JSTAdb\temp.xml"
' APPEND TO TABLES
Application.ImportXML "C:\JSTAdb\temp.xml", acAppendData
strFile = Dir()
Wend
'RELEASE DOM OBJECTS
Set xmlDoc = Nothing: Set xslDoc = Nothing: Set newDoc = Nothing
End Sub
I figured it out. The .xml files were from an InfoPath form and contained a number of large photo attachments. I wasn't waiting long enough for the result to be Transformed. I just needed a bit of patience. It's working OK now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.