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'
Retrieve top level XML node name with XmlSlurper
-
01-07-2022 - |
题
Given the following XML how can I obtain the value of status with Groovy's XmlSlurper:
<response status="success">
<child>
<age>21</age>
<name>Jane McCoy</name>
</child>
</response>
解决方案
不隶属于 StackOverflow