Loading XML file from httprequest output

2019-03-03 10:54发布

问题:

I am trying to analyse the output of httprequest which is formatted as XML. I use MSXML2.DOMDocument to load the response as XML but I receive this error:

The system cannot find the path specified.

this is the output of httprequest when I receive it as ResponseText:

<?xml version="1.0" encoding="utf-8"?>
<resultObj>
  <result>False</result>
  <invoiceNumber>1</invoiceNumber>
  <referenceNumber>21669145</referenceNumber>
  <transactionDate>2016/05/18 20:10:07</transactionDate>
</resultObj>

and this is my Vbscript code to load the result as XML file:

data= "invoiceUID=1"
Set httpRequest = Server.CreateObject("MSXML2.XMLHTTP.6.0")
httpRequest.Open "POST", "https://some url", False
httpRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.Send data

postResponse = httpRequest.ResponseXML.xml

Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load(postResponse) ///// I think this line fails

If xmlDOM.ParseError <> 0 Then
  response.write xmlDOM.ParseError.Reason
Else
  response.write "file loaded"
End If

回答1:

You are using the load method, which

Loads an XML document from the specified location.

However you want to load the XML as a string into the object, so use loadXML, which

Loads an XML document using the supplied string.