fork(1) download
  1. def expectedMap = [Key1: 'Value1', Key2: 'Value2', Key40: 'Value40']
  2.  
  3. def xmlString = """<soap:Envelope xmlns:soap="http://w...content-available-to-author-only...3.org/2003/05/soap-envelope" xmlns:xsi="http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance" xmlns:xsd="http://w...content-available-to-author-only...3.org/2001/XMLSchema">
  4. <soap:Body>
  5. <ArrayOfallObjects>
  6. <ArrayOfObjects>
  7. <Key>Key1</Key>
  8. <Value>Value1</Value>
  9. </ArrayOfObjects>
  10. <ArrayOfObjects>
  11. <Key>Key2</Key>
  12. <Value>Value2</Value>
  13. </ArrayOfObjects>
  14. <ArrayOfObjects>
  15. <Key>Key40</Key>
  16. <Value>Value40</Value>
  17. </ArrayOfObjects>
  18. </ArrayOfallObjects>
  19. </soap:Body>
  20. </soap:Envelope>"""
  21.  
  22. def xml = new XmlSlurper().parseText(xmlString)
  23. def actualMap = xml.'**'.findAll {it.name() == 'ArrayOfObjects' }.collectEntries {[(it.Key.text()): it.Value.text()]}?.sort {it.key}
  24. println "Actual data retrieved: $actualMap"
  25. assert expectedMap == actualMap
Success #stdin #stdout 1.13s 4456448KB
stdin
Standard input is empty
stdout
Actual data retrieved: [Key1:Value1, Key2:Value2, Key40:Value40]