如何从 xml 响应中获取correlationID值,但是使用空手道框架它有一些不同的格式?

问题描述 投票:0回答:1

对于一个 SOAP API 调用,我们得到如下所示的响应(发送虚拟响应)。

--uuid:123456
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">

<soap:Header>
  <m:Trans xmlns:m="https://www.w3schools.com/transaction/"
  soap:mustUnderstand="1">234
  </m:Trans>
</soap:Header>
<success>true</success>
<correlationId>123456abcd</correlationId>
...
...
</soap:Envelope>
--uuid:123456--

我需要从 xml 响应中获取correlationId(123456abcd)值。

我尝试了以下方法。

  1. 替换值不起作用

    • def corrId = response.replace(/.([^<]+)./, '$1')

尝试使用如此多的逻辑和正则表达式来实现此目的,但没有任何效果,您能帮助我们吗?

谢谢。

xml karate
1个回答
0
投票

您应该能够在一行中获取该 id,如下所示:

* def id = //correlationId
© www.soinside.com 2019 - 2024. All rights reserved.