ASP中的XML解析器

时间:2016-07-17 13:51:11

标签: xml asp-classic

这是我的Asp Classic代码,它正在调用Web服务但是当我添加XML解析器代码然后它不起作用。“strResult”显示Web服务的结果但是当我加载此变量进行解析时它不起作用并显示空白。

  <%
        Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")
        Dim strRequest, strResult, strFunction, strURL, strNamespace
        'URL to SOAP namespace and connection URL
        strNamespace = "http://webservice/BranchList"
        strURL = "http://100.000.10.002:881/Corporate/services/Config"

        'function you want to call
        strFunction = "wsGetBranchList"
        'strFunction = "test" 'no parameters required
        strRequest ="<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">"_
        & "    <soapenv:Body>"_
        & "      <wsGetBranchList xmlns=""http://webservice.gms.com.my"">"_
        & "          <wsGetBranchListReq><![CDATA[<WsGetBranchListReq><WsAuth><WsClientName>Tester</WsClientName><Password>1233445664</Password></WsAuth></WsGetBranchListReq>]]></wsGetBranchListReq>"_
        & "       </wsGetBranchList>"_
        & "   </soapenv:Body>"_
        & " </soapenv:Envelope>"
        objXMLHTTP.open "post", "" & strURL & "", False
        objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
        objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest)
        objXMLHTTP.setRequestHeader "SOAPAction", strNamespace & "#" & strFunction
        'send the request and capture the result
        Call objXMLHTTP.send(strRequest)
        strResult = objXMLHTTP.responseText
        'display the XML
        response.write strResult

'Above Part of the code working but when i added parser code it is not working
'I want to load "strResult" as variable

Set objXMLDoc = Server.CreateObject("Microsoft.XMLDOM") 
objXMLDoc.async = False 
objXMLDoc.loadXML(strResult) 
Set Root = objXMLDoc.documentElement
Set NodeList = Root.getElementsByTagName("ServiceStatus")

For i = 0 to NodeList.length -1
  Set TotalTicketIssued1 = objXMLDoc.getElementsByTagName("TotalTicketIssued")
  Set AvgWtSec1 = objXMLDoc.getElementsByTagName("AvgWtSec")(i)
  Set AvgStSec1 = objXMLDoc.getElementsByTagName("AvgStSec")(i)
  Set ServiceName1 = objXMLDoc.getElementsByTagName("ServiceName")(i)
  response.write ServiceName1.text + AvgStSec1.text + AvgWtSec1.text
 Next
 Set objXMLDoc = Nothing

        %>

Xml响应如下所示:

<ServiceStatusList>
  <ServiceStatus>
    <Service>
      <IndService>
        <ServiceNo>1</ServiceNo>
        <ServiceName>Commercial Registration</ServiceName>
      </IndService>
    </Service>
    <CounterOpened>0</CounterOpened>
    <TotalTicketWaiting>0</TotalTicketWaiting>
    <TotalTicketIssued>0</TotalTicketIssued>
    <TotalTicketCalled>0</TotalTicketCalled>
    <TransferTicketIssued>0</TransferTicketIssued>
    <CurrTicketStr>0</CurrTicketStr>
    <NextTicketStr>1001</NextTicketStr>
    <CurrTicket>0</CurrTicket>
    <NextTicket>1001</NextTicket>
    <AvgWtSec>0.0</AvgWtSec>
    <AvgStSec>0.0</AvgStSec>
    <TgtStSec>300.0</TgtStSec>
    <TgtWtSec>480.0</TgtWtSec>
    <TotalWithinTgtWtPer>0.0</TotalWithinTgtWtPer>
    <TotalWithinTgtStPer>0.0</TotalWithinTgtStPer>
    <TotalWithinTgtTtPer>0.0</TotalWithinTgtTtPer>
    <TotalTicketRenegaded>0</TotalTicketRenegaded>
  </ServiceStatus>
</ServiceStatusList>

0 个答案:

没有答案