如何使用空手道dsl读取CDATA元素

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

我的XML请求看起来像这样:

  • def ref = ref.substring(0,end)

  <ns:complete>

     <ns:identifier>23265</ns:identifier>

     <ns:taskData><![CDATA[<sch:SubscriptionApprovalResponse xmlns:sch="http://workflow.subscription.apimgt.carbon.wso2.org">

    <sch:status>APPROVED</sch:status>

    <sch:workflowExternalRef>#(ref)</sch:workflowExternalRef>

    <sch:description></sch:description>

    </sch:SubscriptionApprovalResponse>]]></ns:taskData>

  </ns:complete>

我在CDATA体内从外面传递#(ref),但它没有读它。

我做错了吗?

dsl karate
1个回答
0
投票

是的,因为您正在尝试在CDATA部分中使用嵌入式表达式。没有一个完整的工作例子,我不能说。

您应该分两步执行此操作或使用字符串replacehttps://github.com/intuit/karate#replace

* def baz = 'blah'
* def foo = <bar>#(baz)</bar>
* def xml = <foo><Response><![CDATA[#(foo)]]></Response></foo>
* match xml == <foo><Response><![CDATA[<bar>blah</bar>]]></Response></foo>

* def xml = <foo><Response><![CDATA[<bar>@@baz@@</bar>]]></Response></foo>
* replace xml.@@baz@@ = 'blah'
* match xml == <foo><Response><![CDATA[<bar>blah</bar>]]></Response></foo>
© www.soinside.com 2019 - 2024. All rights reserved.