鉴于以下XML,我如何使用Groovy的XmlSlurper获取status的值:
<response status="success">
<child>
<age>21</age>
<name>Jane McCoy</name>
</child>
</response>
答案 0 :(得分:2)
def xmlStr = """
<response status="success">
<child>
<age>21</age>
<name>Jane McCoy</name>
</child>
</response>
"""
def parsed = new XmlSlurper().parseText(xmlStr)
assert parsed.'@status' == 'success'