Groovy 使用XmlSlurper检索顶级XML节点名称

Groovy 使用XmlSlurper检索顶级XML节点名称,groovy,xmlslurper,Groovy,Xmlslurper,给定以下XML,如何使用Groovy的XmlSlurper获得status的值: <response status="success"> <child> <age>21</age> <name>Jane McCoy</name> </child> </response> 21 简·麦考伊 def xmlStr=”“” 21 简·麦考伊 """ def parsed=ne

给定以下XML,如何使用Groovy的XmlSlurper获得status的值:

<response status="success">
  <child>
     <age>21</age>
     <name>Jane McCoy</name>
  </child>
</response>

21
简·麦考伊
def xmlStr=”“”
21
简·麦考伊
"""
def parsed=new XmlSlurper().parseText(xmlStr)
断言已解析。'@status'='success'
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'