I have an API response in an xml format which I request via vba and want to store in an xml file.
Here is the relevant part of my code:
Dim objFSO As Scripting.FileSystemObject
Dim OUTPUT_file As Object
Dim objXMLHTTP As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
xml_file_path = ThisWorkbook.path & "\XML-Files\" & job_id & ".xml"
Set OUTPUT_file = objFSO.CreateTextFile(xml_file_path, True, True)
'API Request with objXMLHTTP Object
If objXMLHTTP.readyState = 4 Then
OUTPUT_file.Write objXMLHTTP.responseText
OUTPUT_file.Close
End If
At a later point I want to load the xml files back into the application. I do this with the following code:
Set objXML = New MSXML2.DOMDocument60
objXML.Load (xml_file_path)
MsgBox objXML.parseError.reason
'returns: "Switch from current encoding to specified encoding not supported."
Unfortunately the xml file's content is not recognized. (The objXML object stays empty).
The file itself looks good. When viewing it with a text editor, I can see the content.
Loading the xml files from other sources works fine. I therefore expect the problem to be somewhere where I create and write the file.
What am I missing?