Skip to content

Instantly share code, notes, and snippets.

@ponkichi7
Created February 29, 2012 02:43
Show Gist options
  • Save ponkichi7/1937155 to your computer and use it in GitHub Desktop.
Save ponkichi7/1937155 to your computer and use it in GitHub Desktop.
GroovyでXML
import groovy.xml.MarkupBuilder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.example() {
person(name: 'hoge', type: 'hage'){
city('Tokyo')
remarks('特に無し')
}
person(name: 'moge', type: 'debu', foo: 'bar'){
city('Saitama')
remarks('だ埼玉って言わないで')
}
}
def doc = new XmlSlurper().parseText(writer.toString())
println "city=${doc.person.find { it.@type == 'debu' }.city}"
出力結果:
city=Saitama
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment