Groovy web console

subscribe to the feed Subscribe
to this
parse xml and retrieve value (via #groovywebconsole)
tweet this snippet Tweet

parse xml and retrieve value

Published 1 year ago by nmrao with tags parse xml
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def xml = """<soap:Envelope xmlns:soap="" xmlns:xsd="" xmlns:xsi=""> <soap:Body>   <Response xmlns="">      <DataReturn xmlns="">         <additionalData xsi:nil="true" xmlns=""/>         <message xmlns="">Success</message>         <returnCode xmlns="">0</returnCode>      </DataReturn>      <score xmlns="">410</score>      <sets xmlns="">         <sets_InnerSet xmlns="">            <visibleSetsInnerSet>               <set_cd>QS1</set_cd>            </visibleSetsInnerSet>            <visibleSetsInnerSet>               <set_cd>QS8</set_cd>            </visibleSetsInnerSet>            <visibleSetsInnerSet>               <set_cd>QS9</set_cd>            </visibleSetsInnerSet>         </sets_InnerSet>      </sets>      <responseCode xmlns="">success</responseCode>   </Response> </soap:Body> </soap:Envelope>"""
def parsedXml = new XmlSlurper().parseText(xml)
def result = parsedXml.'**'.findAll { == 'set_cd'}.collect{it.text().trim()}.join(',')
println result
assert result instanceof String