您好,我正在尝试替换结构第二层中的一个节点,例如下面的“两个”节点(我想复制该节点及其子节点)
<root>
<first>1</first>
<second>
<one>1</one>
<two>
<a>a</a>
<b>b</b>
<c>c</c>
</two>
<three>c</three>
</second>
<third>3</third>
</root>
所以它最终看起来像这样:
<root>
<first>1</first>
<second>
<one>1</one>
<two>
<a>a</a>
<b>b</b>
<c>c</c>
</two>
<two>
<a>a</a>
<b>b</b>
<c>c</c>
</two>
<three>c</three>
</second>
<third>3</third>
</root>
这在 Karate 中可以做到吗?
非常感谢
最佳答案
通常我不推荐“太聪明”的测试 - 每个 Scenario
都应该专注于一个“静态”有效负载 - 稍后当你尝试阅读你的测试时你会感谢自己。
还要确保您查看了这组“模板化”想法的示例:xml.feature
但不管怎样,给你:
* def root =
"""
<root>
<first>1</first>
<second>
<one>1</one>
<two>
<a>a</a>
<b>b</b>
<c>c</c>
</two>
<three>c</three>
</second>
<third>3</third>
</root>
"""
* xmlstring two = $root/root/second/two
* replace root.<three>c</three> = two + '<three>c</three>'
* xml root = root
* print root
关于api - 如何在 Karate 中复制节点及其子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59259687/