Groovy web console

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

test variable element

Published 4 months ago by nmrao with tags variable element
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
enum DataSort{REQUEST,RESPONSE}
Map<DataSort,String> xmlTag = [(DataSort.REQUEST):'input_parameters', (DataSort.RESPONSE):'output_parameters']

def exportSimulator = { 
        DataSort dataSort= DataSort.REQUEST
        def rootNode = new XmlSlurper().parseText(
"""     
<root>
    <api> 
        <input_parameters> 
            Success
        </input_parameters>
    </api>
</root>
""")
        def field = rootNode.api."${xmlTag[dataSort]}"
        println field.text().trim()
}
exportSimulator()