0

给定以下 XML,我如何使用 Groovy 的 XmlSlurper 获取状态值:

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

1 回答 1

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'
于 2013-10-18T02:19:38.673 回答