soapUI:当多个结果实体 return 及其顺序可能不同时,寻找 xpath 表达式以从响应中捕获特定值
soapUI: looking for xpath expression to capture specific value from response when multiple result entities return and its order may vary
我有一个 API 调用,它可能 return 超过 1 个结果实体。结果实体的顺序可能会有所不同。我如何捕获 "state"(实体中的另一个字段)为 "INPROGRESS" 的特定实体的 executionID。是否有为此使用 xpath 表达式之类的解决方案?
这是示例响应 --
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<bns:queryResponse xmlns:bns="http://api.xyz.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<bns:results numberOfResults="3">
<bns:result xsi:type="bns:ExecutionRecord">
<bns:executionId>execution1-5b041417-691b-4f56-b1d4-2b2d35cb5353</bns:executionId>
<bns:account>account1</bns:account>
<bns:executionTime>2015-06-24T16:31:25Z</bns:executionTime>
<bns:status>ERROR</bns:status>
</bns:result>
<bns:result xsi:type="bns:ExecutionRecord">
<bns:executionId>execution2-5b041417-691b-4f56-b1d4-2b2d35cb5353</bns:executionId>
<bns:account>account1</bns:account>
<bns:executionTime>2015-06-24T16:31:25Z</bns:executionTime>
<bns:status>INPROGRESS</bns:status>
</bns:result>
</bns:result>
<bns:result xsi:type="bns:ExecutionRecord">
<bns:executionId>execution3-5b041417-691b-4f56-b1d4-2b2d35cb5353</bns:executionId>
<bns:account>account1</bns:account>
<bns:executionTime>2015-06-24T16:31:25Z</bns:executionTime>
<bns:status>ERROR</bns:status>
</bns:result>
</bns:result>
</bns:results>
</bns:queryResponse>
</S:Body>
</S:Envelope>
如前所述,您的 XML 样本已损坏。但是那里已经足够了,您应该能够使用类似以下 XPath 的内容:
//*:status[text()='INPROGRESS']/preceding-sibling::*:executionId/text()
这使用 "axis" 首先找到包含您的文本的状态节点,然后是它的兄弟 executionId 节点。
或者,类似这样的方法也应该有效:
//*:result[*:status[text()='INPROGRESS']]/*:executionId/text()
这只是找到结果节点,其中包含您的状态节点和 returns 那个 executionId。
有关 XPath 的其他信息可以是 found here。
我有一个 API 调用,它可能 return 超过 1 个结果实体。结果实体的顺序可能会有所不同。我如何捕获 "state"(实体中的另一个字段)为 "INPROGRESS" 的特定实体的 executionID。是否有为此使用 xpath 表达式之类的解决方案? 这是示例响应 --
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<bns:queryResponse xmlns:bns="http://api.xyz.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<bns:results numberOfResults="3">
<bns:result xsi:type="bns:ExecutionRecord">
<bns:executionId>execution1-5b041417-691b-4f56-b1d4-2b2d35cb5353</bns:executionId>
<bns:account>account1</bns:account>
<bns:executionTime>2015-06-24T16:31:25Z</bns:executionTime>
<bns:status>ERROR</bns:status>
</bns:result>
<bns:result xsi:type="bns:ExecutionRecord">
<bns:executionId>execution2-5b041417-691b-4f56-b1d4-2b2d35cb5353</bns:executionId>
<bns:account>account1</bns:account>
<bns:executionTime>2015-06-24T16:31:25Z</bns:executionTime>
<bns:status>INPROGRESS</bns:status>
</bns:result>
</bns:result>
<bns:result xsi:type="bns:ExecutionRecord">
<bns:executionId>execution3-5b041417-691b-4f56-b1d4-2b2d35cb5353</bns:executionId>
<bns:account>account1</bns:account>
<bns:executionTime>2015-06-24T16:31:25Z</bns:executionTime>
<bns:status>ERROR</bns:status>
</bns:result>
</bns:result>
</bns:results>
</bns:queryResponse>
</S:Body>
</S:Envelope>
如前所述,您的 XML 样本已损坏。但是那里已经足够了,您应该能够使用类似以下 XPath 的内容:
//*:status[text()='INPROGRESS']/preceding-sibling::*:executionId/text()
这使用 "axis" 首先找到包含您的文本的状态节点,然后是它的兄弟 executionId 节点。
或者,类似这样的方法也应该有效:
//*:result[*:status[text()='INPROGRESS']]/*:executionId/text()
这只是找到结果节点,其中包含您的状态节点和 returns 那个 executionId。
有关 XPath 的其他信息可以是 found here。