Groovy web console

subscribe to the feed Subscribe
to this
site
cdata (via #groovywebconsole)
tweet this snippet Tweet
this
script

cdata

Published 4 weeks ago by nmrao with tags cdata
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def xml = """<soap:Envelope xmlns:soap="schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="w3.org/2001/XMLSchema-instance" xmlns:xsd="w3.org/2001/XMLSchema">
    <soap:Body>
        <GetAtomicWeightResponse xmlns="webserviceX.NET">
            <GetAtomicWeightResult><![CDATA[<NewDataSet><Table><AtomicWeight>12.0115</AtomicWeight></Table></NewDataSet>]]></GetAtomicWeightResult>
        </GetAtomicWeightResponse>
    </soap:Body>
</soap:Envelope>"""
def getData = { data, element -> new XmlSlurper().parseText(data).'**'.find{it.name() == element} }
def atomicWeight = getData((getData(xml, 'GetAtomicWeightResult') as String).trim(), 'AtomicWeight').text()
println atomicWeight