I am using the following code in MSAccess VBA to acquire some XML data. Periodically the loadXML call on line 99 returns false. What types of conditions could be responsible for this? The code is based on a vendor's example. Perhaps it's incomplete? Any help would be appreciated. Dim oXMLHTTP As XMLHTTP ' is msxml6.dll Dim oDoc As DOMDocument Dim oList As IXMLDOMNodeList Dim oElem As IXMLDOMElement Dim oNode As IXMLDOMNode Dim strError As String Dim strEDocPath As String Dim strEDocFile As String Const cErrInTUResponse = 65210 Const cErrResourceNotFound = -2146697211 83 86 Set oDoc = New DOMDocument 87 oDoc.async = False ' cbfXML returns a well formed XML document 88 oDoc.loadXML cbfXML() 89 If (oDoc.parseError.ErrorCode <> 0) Then 90 Err.Raise oDoc.parseError.ErrorCode, Me.Name & ".cbfReport", oDoc.parseError.Reason & "; " & oDoc.parseError.srcText 91 End If 92 ' post and get the reply 94 Set oXMLHTTP = New XMLHTTP 95 Call SysCmd(acSysCmdSetStatus, "Connecting...") 96 oXMLHTTP.Open "POST", "https://RemovedForDiscussion", 0 97 Call SysCmd(acSysCmdSetStatus, "Waiting...") 98 oXMLHTTP.Send oDoc DoEvents 99 If Not oDoc.loadXML(oXMLHTTP.responsexml.xml) Then 100 strError = "An unexpected error occured. LoadXML failed. " 101 Error cErrInTUResponse 102 Else ' check that the document loaded 104 If oDoc.documentElement Is Nothing Or Len(oDoc.xml) = 0 Then 105 strError = "An unexpected error occured. Nothing was returned. " 106 Error cErrInTUResponse 107 End If Patrick =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Patrick Jackman Vancouver, BC 604-874-5774
Patrick Jackman wrote: > 99 If Not oDoc.loadXML(oXMLHTTP.responsexml.xml) Then > 100 strError = "An unexpected error occured. LoadXML failed. " > 101 Error cErrInTUResponse If you already have responseXML then there is no need at all to use loadXML. Simply check oXMLHTTP.responseXML.parseError.errorCode/reason to find any errors in the XML you have received. And I don't know much about VBA and stuff like DoEvents but usually with MSXML and XMLHTTP you would either make an asynchronous request by passing True as the third argument of the open method or you would make a synchronous request by passing False as the third argument. Then, to process the response in the case of an asynchronous request you set up an onreadystatechange event handler on the XMLHTTP object. In the case of a synchronous request the send call block and you can process the response status after the send call. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
"Martin Honnen" wrote in message news:eTrVATUzIHA.4816@TK2MSFTNGP03.phx.gbl... > > And I don't know much about VBA and stuff like DoEvents In case it helps, DoEvents is essentially a message loop. If you don't know what that is then think of it as something that allows pending events to be processed.
Thanks for your suggestions Martin. They are much appreciated. Patrick. "Martin Honnen" wrote in message news:eTrVATUzIHA.4816@TK2MSFTNGP03.phx.gbl... Patrick Jackman wrote: > 99 If Not oDoc.loadXML(oXMLHTTP.responsexml.xml) Then > 100 strError = "An unexpected error occured. LoadXML failed. " > 101 Error cErrInTUResponse If you already have responseXML then there is no need at all to use loadXML. Simply check oXMLHTTP.responseXML.parseError.errorCode/reason to find any errors in the XML you have received. And I don't know much about VBA and stuff like DoEvents but usually with MSXML and XMLHTTP you would either make an asynchronous request by passing True as the third argument of the open method or you would make a synchronous request by passing False as the third argument. Then, to process the response in the case of an asynchronous request you set up an onreadystatechange event handler on the XMLHTTP object. In the case of a synchronous request the send call block and you can process the response status after the send call. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
"Patrick Jackman" wrote in message news:%23A%23TgiLzIHA.4816@TK2MSFTNGP03.phx.gbl... > I am using the following code in MSAccess VBA to acquire some XML data. > Periodically the loadXML call on line 99 returns false. What types of > conditions could be responsible for this? The code is based on a vendor's > example. Perhaps it's incomplete? > > Any help would be appreciated. > > Dim oXMLHTTP As XMLHTTP ' is msxml6.dll > Dim oDoc As DOMDocument > Dim oList As IXMLDOMNodeList > Dim oElem As IXMLDOMElement > Dim oNode As IXMLDOMNode > Dim strError As String > Dim strEDocPath As String > Dim strEDocFile As String > Const cErrInTUResponse = 65210 > Const cErrResourceNotFound = -2146697211 > 83 > 86 Set oDoc = New DOMDocument > 87 oDoc.async = False > ' cbfXML returns a well formed XML document > 88 oDoc.loadXML cbfXML() > 89 If (oDoc.parseError.ErrorCode <> 0) Then > 90 Err.Raise oDoc.parseError.ErrorCode, Me.Name & ".cbfReport", > oDoc.parseError.Reason & "; " & oDoc.parseError.srcText > 91 End If > 92 > ' post and get the reply > 94 Set oXMLHTTP = New XMLHTTP > 95 Call SysCmd(acSysCmdSetStatus, "Connecting...") > 96 oXMLHTTP.Open "POST", "https://RemovedForDiscussion", 0 > 97 Call SysCmd(acSysCmdSetStatus, "Waiting...") > 98 oXMLHTTP.Send oDoc > DoEvents > 99 If Not oDoc.loadXML(oXMLHTTP.responsexml.xml) Then > 100 strError = "An unexpected error occured. LoadXML failed. " > 101 Error cErrInTUResponse > 102 Else > ' check that the document loaded > 104 If oDoc.documentElement Is Nothing Or Len(oDoc.xml) = 0 Then > 105 strError = "An unexpected error occured. Nothing was > returned. " > 106 Error cErrInTUResponse > 107 End If > Yes the code is incomplete. There are all sorts of reasons that will could cause a the HTTP post to fail. On return from a synchronous call to .Send (which you are doing) the code should test that the oXMLHTTP.Status is 200. If not then the POST failed in some way. The Status code indicates what went wrong. -- Anthony Jones - MVP ASP/ASP.NET