Import XML

Could not get the foreign language to import. Not sure why.
Lets see if you can appreciate this code.
Located an XML tutor page with some simple examples.
Hope some others at this site can take this example and improve or modify it - to share with the rest of us.

Code:
Public Sub Transform(sourceFile, stylesheetFile, resultFile)
      ' For Access 2010 VBA  ----> Menu Tools Reference   choose  Microsoft XML, 6.0
      ' Example of using Access VBA to grab an XML file from the web (or file location)
      ' that has 2nd site with a Style Sheet.
      Dim source As New MSXML2.DOMDocument30
      Dim stylesheet As New MSXML2.DOMDocument30
      Dim result As New MSXML2.DOMDocument30
      ' Load data.
10    source.async = False
20    source.Load sourceFile
      ' Load style sheet.
30    stylesheet.async = False
40    stylesheet.Load stylesheetFile
50    If (source.parseError.ErrorCode <> 0) Then
60       MsgBox ("Error loading source document: " & source.parseError.Reason)
70       Else
80    If (stylesheet.parseError.ErrorCode <> 0) Then
90          MsgBox ("Error loading stylesheet document: " & stylesheet.parseError.Reason)
100      Else
            ' Do the transform.
110         source.transformNodeToObject stylesheet, result
120         result.Save resultFile
130   End If
140   End If
150   Debug.Print "Error is " & Err.Number
' To run the above - This is a web site that has simple XML sites
' The example is a XML file with an associated XML Style Sheet
' To run the above code - and save the result in C:\MyFolder
' Transform "http://www.w3schools.com/xml/simplexsl.xml", _
    "http://www.w3schools.com/xml/simple.xsl", _
    "C:\myfolder\AtemptempImport.xml"
' Rx_


End Sub

My new submission is awaiting approval on Code Reository
It has two methods - one puts the XML into a file as shown above.
The second code sample creates a new table - creates the header - and populates the data.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom