【发布时间】:2018-05-16 06:08:40
【问题描述】:
我需要从一个 api 的响应中提取子元素,然后将其动态传递给下一个 api 请求。
假设我有以下 xml:
* def foo =
"""
<records>
<record index="1">a</record>
<record index="2">b</record>
<record index="3" foo="bar">c</record>
</records>
"""
我只想提取这个:
<record index="1">a</record>
<record index="2">b</record>
<record index="3" foo="bar">c</record>
我尝试了以下选项,但都没有成功:
* def chk = foo//records/*
* def chk = foo//records/child::*
* def chk = foo//records/descendant::*
* print chk
打印后,我得到以下内容,如果我遗漏了什么或任何其他方法,请提出建议。谢谢!
13:51:07.046 INFO - [print] {
"records": {
"record": [
{
"_": "a",
"@": {
"index": "1"
}
},
{
"_": "b",
"@": {
"index": "2"
}
},
{
"_": "c",
"@": {
"foo": "bar",
"index": "3"
}
}
]
}
}
【问题讨论】:
标签: karate