有没有办法使用RestAssured的“XmlPath”来返回节点列表,而不是字符串列表?
import com.jayway.restassured.path.xml.XmlPath
def xml = '''
<stooges>
<stooge name="larry">
<hair>curly</hair>
<tagline>I'm not sure about this...</tagline>
</stooge>
<stooge name="curly">
<hair>bald</hair>
<tagline>Nyuk! Nyuk! Nyuk!</tagline>
</stooge>
<stooge name="moe">
<hair>bowl</hair>
<tagline>Why I oughtta...</tagline>
</stooge>
</stooges>
'''
def pathData = XmlPath.from(xml)
// this will run, but it gives me a single-item list of strings. I can't navigate the tree from there
def listOfStrings = pathData.getList("stooges.stooge.**.findAll {it.name() == 'hair' && it.text() == 'bald'}")
// this fails with
// Caught: java.lang.ClassCastException: Cannot convert class java.lang.String to interface com.jayway.restassured.path.xml.element.Node
def thisWillFail = pathData.getNode("stooges.stooge.**.findAll { it.name() == 'hair' && it.text() == 'bald'}")
1条答案
按热度按时间hgtggwj01#
印刷品: