带VBS名称空间的XPath

时间:2016-10-11 10:07:31

标签: xml xpath

我正在尝试从以下xml中检索几个节点:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <CheckPersonResponse xmlns="http://test.net/crs/">
         <CheckPersonResult>
            <xml xmlns="http://test.com/webservices/crs2/">
               <requestid>933ca7df-6f25-49d9-8144-692e9f18cf27</requestid>
               <customernumber>xxx</customernumber>
               <reference>xx</reference>
               <product>xxx</product>
               <input>
                  <customernumber>xx</customernumber>
                  <reference>xx</reference>
                  <name>xx</name>
                  <initials>xx</initials>
                  <prefix>xx</prefix>
                  <gender>xx</gender>
                  <birthdate>xxx</birthdate>
                  <streetname>x</streetname>
                  <housenumber>x</housenumber>
                  <extension>Axx</extension>
                  <postcode>xx</postcode>
                  <city>xx</city>
                  <country />
                  <phonenumber1 />
                  <phonenumber2 />
                  <emailaddress />
                  <bankaccount />
                  <referencedate>xxx</referencedate>
                  <typeofclaim>xx</typeofclaim>
                  <claimdate>xxx</claimdate>
                  <claimamount>xx</claimamount>
               </input>
               <result>
                  <reference>xxx</reference>
                  <personalscore>0</personalscore>
                  <statisticalscore>0</statisticalscore>
                  <paymentscore>0</paymentscore>
                  <overallscore>0</overallscore>
                  <addressindicator />
               </result>
            </xml>
         </CheckPersonResult>
      </CheckPersonResponse>
   </soap:Body>
</soap:Envelope>

我想要检索标记<result>中的所有节点我如何选择带有XPath的所有节点并在VBS中使用它们?

1 个答案:

答案 0 :(得分:1)

找到解决方案:

namespaces = Array( _
  "xmlns:s='http://test.nl/webservices/crs2/'", _
  "xmlns:c='http:/test.net/crs/'", _
  "xmlns:soap='http://www.w3.org/2003/05/soap-envelope'", _
  "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'", _
  "xmlns:xsd='http://www.w3.org/2001/XMLSchema'" _
)

xmlhttp.responseXML.setProperty "SelectionNamespaces", Join(namespaces, " ")

xpath = "/soap:Envelope/soap:Body/c:CheckPersonResponse/c:CheckPersonResult/s:xml/s:result/s:*"
Set NodeList = xmlhttp.responseXML.selectNodes(xpath)