Groovy web console

subscribe to the feed Subscribe
to this
site
extract data from xml (via #groovywebconsole)
tweet this snippet Tweet
this
script

extract data from xml

Published 6 months ago by nmrao with tags parse
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def xml = """<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <SignResult xmlns="http://www.tw.com/tsswitch">
         <Result>
            <Code>OK</Code>
            <Desc>The operation completed successfully</Desc>
         </Result>
         <SignedDocument>TUlNRS1WZXJzaW9uOiAxLjANCkRhdGU6IFdlZCwgMTkgQXByIDIwMTcgMDY6MDA6NDMgKzINCkNvbnRlbnQtVHlwZTogbXVsdGlwYXJ0L3NpZ25lZDsgcHJvdG9jb2w9ImFwcGxpY2F0aW9uL3BrY3M3LXNpZ25hdHVyZSI7IG1pY2FsZz0NCg==</SignedDocument>
         <Details>success</Details>
      </SignResult>
   </soap:Body>
</soap:Envelope>"""

println new XmlSlurper().parseText(xml).'**'.find {it.name() == 'SignedDocument'}.text()