Question

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>
Était-ce utile?

La solution

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'
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top