开发者

assertion with Xpath

开发者 https://www.devze.com 2023-01-05 18:53 出处:网络
I\'m trying to assert SOAP response by using Xpath to select particular nodes, here is my XML response

I'm trying to assert SOAP response by using Xpath to select particular nodes, here is my XML response

<return>
<contactList>
               <contacts>
                  <person>
                     <contactId>3426</contactId>
                     <pers开发者_运维百科onName>
                        <names>
                              <firstName>Cosi</firstName>
                              <lastName>Como</lastName>
                              <middleName>Midi</middleName>
                        </names>
                     </personName>
                  </person>
                  </contacts>
            </contactList>
</return>

I'm trying to get contactId value, I tried both this //contactList/contacts/person[contactId='3426']/contactId and //*[local-name()='contactList'] /contacts/person[contactId='3426'] and none work I get this result No Nodes Matched how? this is valid xpath syntax and valid path is there an alternative?


Without seeing the full-blown SOAP message, I can't be certain, but my first guess would be namespaces.

The use of local-name() in one of your queries implies to me that you are using non-empty namespaces. But even in your second query, the reference to "contacts" without specifying a namespace would cause the XPath to fail if the node actually has a non-blank namespace.

Try //*[local-name()='contactList'] and see if you get the "contactList" node.

0

精彩评论

暂无评论...
验证码 换一张
取 消