Karate 空手道-[#文档:空]在输出中

Karate 空手道-[#文档:空]在输出中,karate,Karate,我使用正则表达式删除了XML中一些不需要的项。现在,我需要打印包含多个子元素的所有includedService节点 这是我使用的代码 * string test = read('classpath:PP1/data/Test.xml') * string test= test.replaceAll("xsi:nil[^/]*", "") * def Complete_XML = test * def included = $Complete_XML/Envelope/Body/getPrice

我使用正则表达式删除了XML中一些不需要的项。现在,我需要打印包含多个子元素的所有includedService节点

这是我使用的代码

* string test = read('classpath:PP1/data/Test.xml')
* string test= test.replaceAll("xsi:nil[^/]*", "")
* def Complete_XML = test
* def included = $Complete_XML/Envelope/Body/getPricePlanResponse/pricePlanSummary/includedService
* print included
如果我运行这个,我会得到下面的响应

20:19:54.169 [ForkJoinPool-1-worker-1] INFO  com.intuit.karate - [print] [
  [#document: null],
  [#document: null]
]
但是,我可以打印includedService节点之外的选定元素。请帮忙


福费蒙特勒临时代办
2009-11-05
计算机辅助设计数据
真的
服务
10
0
0
1.
MBAPN
假的
0
假的
0
1.
MBAPN
假的
0
假的
0

请记住,XML必须始终包装在某个元素或另一个元素中。试试这个:

* def included = $xml/Envelope/Body/getPricePlanResponse/pricePlanSummary//includedService
* def root = <root></root>
* def fun = function(x, i){ karate.set('root', '/includedService[' + (i + 1) + ']', x) }
* eval karate.forEach(included, fun)
* print root
*def included=$xml/Envelope/Body/getPricePlanResponse/pricePlanSummary//includedService
*定义根=
*def fun=function(x,i){karate.set('root','/includedService['+(i+1)+']',x)}
*评估空手道。forEach(包括,乐趣)
*打印根
你应该得到:

<root>
  <ns4:includedService>
    <ns4:term>0</ns4:term>
    <ns4:brandId>1</ns4:brandId>
    <ns4:feature>
      <ns5:code>MBAPN</ns5:code>
      <ns4:type/>
      <ns4:additionalNumberRequiredInd>false</ns4:additionalNumberRequiredInd>
    </ns4:feature>
    <ns4:recurringCharge>0.0</ns4:recurringCharge>
    <ns4:callingCircleFeaturesInd>false</ns4:callingCircleFeaturesInd>
  </ns4:includedService>
  <ns4:includedService>
    <ns4:term>0</ns4:term>
    <ns4:brandId>1</ns4:brandId>
    <ns4:feature>
      <ns5:code>MBAPN</ns5:code>
      <ns4:type/>
      <ns4:additionalNumberRequiredInd>false</ns4:additionalNumberRequiredInd>
    </ns4:feature>
    <ns4:recurringCharge>0.0</ns4:recurringCharge>
    <ns4:callingCircleFeaturesInd>false</ns4:callingCircleFeaturesInd>
  </ns4:includedService>
</root>

0
1.
MBAPN
假的
0
假的
0
1.
MBAPN
假的
0
假的
有关其他想法,请参考以下答案: