2011-05-27 93 views
0

我感觉我正在做一些真正不正确的事情。 在做肥皂时,他们会返回一个xml,其中可能包含或不包含错误。 我想检查是否存在错误,如果没有读取值。 不知何故,我无法抓住它直接:(xpath soap命名空间抓取项目

下面是一些与结果的样品返回和其中一个给出了一个错误(找不到名称)

<?xml version="1.0" encoding="utf-8"?> 
<soapEnvelope 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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <envHeader xmlns:env="http://www.w3.org/2003/05/soap-envelope"> 
     <wsaAction>http://www.rechtspraak.nl/namespaces/ccr01/searchPersonResponse</wsaAction> 
     <wsaMessageID>urn:uuid:b75d2932-5687-4871-9d07-3b74b084978a</wsaMessageID> 
     <wsaRelatesTo>urn:uuid:9112d870-248d-4d07-acd0-d88e4a48d547</wsaRelatesTo> 
     <wsaTo>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsaTo> 
     <wsseSecurity> 
     <wsuTimestamp wsu:Id="Timestamp-061df7b5-32a2-4021-852d-2df98953e076"> 
      <wsuCreated>2011-05-27T12:11:45Z</wsuCreated> 
      <wsuExpires>2011-05-27T12:16:45Z</wsuExpires> 
     </wsuTimestamp> 
    </envHeader> 
    <soapBody> 
     <searchPersonResponse xmlns="http://www.rechtspraak.nl/namespaces/ccr01"> 
      <searchPersonResult> 
       <CCR_WS xmlns="http://www.rechtspraak.nl/namespaces/ccr"> 
        <curandus> 
         <ccn>1</ccn> 
         <cur_voornamen>Jan</cur_voornamen> 
         <cur_voorvoegsels>van</cur_voorvoegsels> 
         <cur_achternaam>Beek</cur_achternaam> 
         <geboorte_datum>1980-01-02</geboorte_datum> 
         <geboorte_plaats>Werkendam</geboorte_plaats> 
        </curandus> 
       </CCR_WS> 
      </searchPersonResult> 
     </searchPersonResponse> 
    </soapBody> 
</soapEnvelope> 

,没有结果

的一个
<?xml version="1.0" encoding="utf-8"?> 
<soapEnvelope 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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <envHeader xmlns:env="http://www.w3.org/2003/05/soap-envelope"> 
     <wsaAction>http://www.rechtspraak.nl/namespaces/ccr01/searchPersonResponse</wsaAction> 
     <wsaMessageID>urn:uuid:b75d2932-5687-4871-9d07-3b74b084978a</wsaMessageID> 
     <wsaRelatesTo>urn:uuid:9112d870-248d-4d07-acd0-d88e4a48d547</wsaRelatesTo> 
     <wsaTo>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsaTo> 
     <wsseSecurity> 
     <wsuTimestamp wsu:Id="Timestamp-061df7b5-32a2-4021-852d-2df98953e076"> 
      <wsuCreated>2011-05-27T12:11:45Z</wsuCreated> 
      <wsuExpires>2011-05-27T12:16:45Z</wsuExpires> 
     </wsuTimestamp> 
    </envHeader> 
    <soapBody> 
     <searchPersonResponse xmlns="http://www.rechtspraak.nl/namespaces/ccr01"> 
      <searchPersonResult> 
       <CCR_WS xmlns="http://www.rechtspraak.nl/namespaces/ccr"> 
        <exceptie errorcode="1">No Results found.</exceptie> 
       </CCR_WS> 
      </searchPersonResult> 
     </searchPersonResponse> 
    </soapBody> 
</soapEnvelope> 

这里是我的代码选择的命名空间,然后检查

​​

肯定有抓 $ lijst更好的办法[0] - > exceptie->属性() - >错误代码

例如...

回答

0

...不知道这是否是一个给每个人“更好的方式”,但是这里有一个直接的XPath表达式来选择错误代码。您可以通过删除步骤并使用//(开头或中间)来缩短效率。属性通过@(或者如果您偏好较长的语法与attribute::轴)来选择。如果attribute(或者exceptie元素)不存在,则不返回任何内容。

/*/*/ccr01:searchPersonResponse/ccr01:searchPersonResult/ccr:CCR_WS/ccr:exceptie/@errorcode 

请记住注册您在XPath表达式中使用的所有命名空间前缀。