使用VBA使用xslt转换文件将XML导入MS Access

时间:2017-10-13 23:03:58

标签: xml vba ms-access xslt

我正在尝试将一堆.xml文件导入Access表。我创建了一个.xslt文件,当我在Access中手动运行导入时,该文件正常工作。但是当我尝试使用VBA代码(我在这里从另一篇文章中提取)来转换.xml文件时,生成的temp.xml文件完全为空。我错过了什么?

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

1 个答案:

答案 0 :(得分:0)

我明白了。 .xml文件来自InfoPath表单,包含许多大型照片附件。我没等足够长时间才能将结果转换成结果。我只需要一点耐心。现在工作正常。