Groovy web console

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

parse xml attribute

Published 6 months ago by nmrao with tags parse xml
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def xml = """<ServerList>
    <Server name="testserver1">
            <CleanUp>
                    <GZIP>
                            <File KeepDays="30">log1</File>
                            <File KeepDays="30">log1.2</File>
                    </GZIP>
            </CleanUp>
    </Server>
    <Server name="testserver2">
            <CleanUp>
                    <GZIP>
                            <File KeepDays="30">log2</File>
                    </GZIP>
            </CleanUp>
    </Server>
    <Server name="testserver3">
            <CleanUp>
                    <GZIP>
                            <File KeepDays="30">log3</File>
                    </GZIP>
            </CleanUp>
    </Server>
</ServerList>"""
def SERVER = 'testserver1'
def serverList = new XmlSlurper().parseText(xml)

println serverList.Server.findAll{it.@name == SERVER}.'**'.findAll{it.name() == 'File'}*.text()