经典的asp和XML解析错误

时间:2012-07-01 20:58:06

标签: asp-classic xmldom

我正在尝试将xml发布到银行。它返回我xml响应。

我正在使用此代码:

Function HTTPPost(sUrl, sRequest)
  set oHTTP = CreateObject("Microsoft.XMLHTTP")
  oHTTP.open "POST", sUrl,false
  oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  oHTTP.setRequestHeader "Content-Length", Len(sRequest)
  oHTTP.send sRequest
  HTTPPost = oHTTP.responseText  
End Function

sonuc = HTTPPost(serviceUrl, requestXML)
Dim objXMLDoc
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load(sonuc)           
Dim Node
Set Node = objXMLDoc.documentElement.selectSingleNode("//RRN")
Response.write Node.text

我正在尝试检索

<RRN>218323000090</RRN>

对象所需的错误:&#39; documentElement&#39;

这是银行回应:

 <?xml version="1.0" encoding="utf-16"?>
    <PosResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <Host>
        <AuthCode />
        <RRN>218323000090</RRN>
        <Date>0701</Date>
        <Time>230834</Time>
        <RC>58</RC>
      </Host>
      <Result>
        <Code>58</Code>
        <Text />
        <ErrorMessage />
      </Result>
      <TrnxID>842c0d26-3abd-4597-ba10-d92674e16303</TrnxID>
      <TrnxType>Sale</TrnxType>
      <CustomData>
        <Item Name="KazanilanPuan" Value="0" />
        <Item Name="KalanPuan" Value="0" />
        <Item Name="HarcananPuan" Value="0" />
        <Item Name="HarcananPara" Value="0" />
      </CustomData>
    </PosResponse>

1 个答案:

答案 0 :(得分:1)

您应该使用loadXML而不是load来加载xml的字符串。
另外,请查看以下内容:

Which version of MSXML should I use?

difference between server.createObject and createobject in asp classic