解析经典ASP中WSDL Web服务生成的XML字符串



我想解析XML字符串WICH是由WebService请求生成的。我拥有的字符串是:

<?xml version="1.0" encoding="utf-8"?>
<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>
    <getPersonBySgidResponse xmlns="http://all.service.xxxxx.com">
      <getPersonBySgidReturn>
        <alternateContactSgi xsi:nil="true"/>
        <birthDate>1986-11-14T22:00:00.327Z</birthDate>
        <birthDateOkay>true</birthDateOkay>
        <branchId>B78</branchId>
        <businessGroupId>R78E</businessGroupId>
        <contractEndDate xsi:nil="true"/>
        <contractStartDate>2013-09-16T22:00:00.327Z</contractStartDate>
        <contractorCompanyName xsi:nil="true"/>
        <countryId>FRA</countryId>
        <delegationId>DLFRA</delegationId>
        <departmentName>xxx</departmentName>
        <departmentNumber>XXXXX</departmentNumber>
        <detailed>true</detailed>
        <divisionName>XXXXO -  SIEGE SOCIAL</divisionName>
        <divisionNumber>31346</divisionNumber>
        <educationCompound xsi:nil="true"/>
        <employeePosition>N</employeePosition>
        <employeePositionLocal xsi:nil="true"/>
        <faxNumber xsi:nil="true"/>
        <filiereId>ADM</filiereId>
        <firstname>Lakhdar</firstname>
        <firstnameEncoded xsi:nil="true"/>
        <firstnamePreferred xsi:nil="true"/>
        <fullName>Lakhdar XXXX</fullName>
        <inChargeSgiJuridic xsi:nil="true"/>
        <inChargeSgiMission xsi:nil="true"/>
      </getPersonBySgidReturn>
    </getPersonBySgidResponse>
  </soapenv:Body>
</soapenv:Envelope>

我必须在"响应"之前添加标签才能看到这样的XML(否则字符串只是所有属性的串联)。

我将此字符串放在" myxml"变量中,然后尝试像这样解析它:

Dim objXML,objRoot ,I, thisNode,strID, strNarrative, thisChild, selectedNode,testStr
    Set objXML= Server.CreateObject("MSXML2.DOMDocument") 
    objXML.async = False    
    objXML.setProperty "SelectionLanguage", "XPath" 
    objXML.setProperty "SelectionNamespaces", "xmlns='http://all.service.xxxxx.com' " & _
        "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' "
    objXML.loadXML(myXML) 
    Set selectedNode= objXML.selectSingleNode("//soapenv:Envelope/soapenv:Body/getPersonBySgidResponse/getPersonBySgidReturn/getPersonBySgidReturn/divisionName")
    Set objRoot = objXML.documentElement 
    Response.Write "<br/> myXml == "  &  myXML
    Response.Write "<br/> objXML == "  &  objXML.Text   
    Response.Write "<br/> objRoot == "  &  objRoot.Text
    Response.Write "<br/> selectedNode == "  &  selectedNode.Text

但是在最后一行,我有错误:需要对象。

希望我写的东西有意义:)谢谢

错误xpath "//soapenv:Envelope/soapenv:Body/getPersonBySgidResponse/getPersonBySgidReturn/getPersonBySgidReturn/divisionName"

从XPath删除一个getPersonBySgidReturn

您的代码线应为

Set selectedNode= objXML.selectSingleNode("//soapenv:Envelope/soapenv:Body/getPersonBySgidResponse/getPersonBySgidReturn/divisionName")

最新更新