【问题标题】:How to extract value from a string in XML response using karate如何使用空手道从 XML 响应中的字符串中提取值
【发布时间】:2018-09-04 16:05:26
【问题描述】:

不幸的是,ei 从我的后端得到的响应不是正确的 xml 格式,它以错误的格式给出响应,如下所示:

<soapenv:Body>

    <ns2:getInputResponse xmlns:ns2="http://docs.oasisopen.org/ns/bpel4people/ws-humantask/api/200803">

        <ns2:taskData xmlns:s186="http://www.w3.org/2001/XMLSchema-instance" xmlns:s187="http://www.w3.org/2001/XMLSchema" s186:type="s187:string">&lt;?xml version="1.0" encoding="UTF-8"?>

&lt;SubscriptionApprovalData xmlns="http://workflow.subscription.apimgt.carbon.wso2.org" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

     &lt;apiName>Auto_Approval&lt;/apiName>

     &lt;apiVersion>v1&lt;/apiVersion>

     &lt;apiContext>/test/lambda/v1&lt;/apiContext>

     &lt;apiProvider>admin&lt;/apiProvider>

     &lt;subscriber>regtest&lt;/subscriber>

     &lt;applicationName>newApp&lt;/applicationName>

     &lt;tierName>Gold&lt;/tierName>

     &lt;workflowExternalRef&gt;23d30bd8-51e3-4afe-aae0-3fa159d85a6b&lt;/workflowExternalRef>

     &lt;callBackURL>https://apistore-dev-dev-a878-14-ams10-nonp.qcpaws.qantas.com.au/services/WorkflowCallbackService&lt;/callBackURL>
  &lt;/SubscriptionApprovalData></ns2:taskData>

    </ns2:getInputResponse>

</soapenv:Body>

现在因为这个空手道无法读取响应并获取“workflowExternalRef”的值,这是我这次测试的目标。

有没有什么方法可以读空手道?

【问题讨论】:

  • 空手道可以做xml解码/编码吗?

标签: dsl karate


【解决方案1】:

这确实是一个混乱的 XML,所以如果可以修复,请与您的团队中的某个人联系。

无论如何,既然您可以在空手道中使用 Java,这里有一种方法可以做到这一点。这不是生产质量代码,请酌情调整:

* string response = response
* def start = response.indexOf('workflowExternalRef&gt;')
* def ref = response.substring(start + 23)
* def end = ref.indexOf('&lt;')
* def ref = ref.substring(0, end)
* match ref == '23d30bd8-51e3-4afe-aae0-3fa159d85a6b'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多