Skip to content

Instantly share code, notes, and snippets.

@ppazos
Last active June 30, 2022 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppazos/50826d54d47b38740c1ecc4687c9eb2b to your computer and use it in GitHub Desktop.
Save ppazos/50826d54d47b38740c1ecc4687c9eb2b to your computer and use it in GitHub Desktop.
Examples with XML serialization in pretty print and ugly print / minified
def xml = new XmlSlurper().parseText('<?xml version="1.0" encoding="utf-8"?><root><one a1="uno!₂"/><two>Some text!</two></root>')
def out = groovy.xml.XmlUtil.serialize(xml)
println out
println out.class // string
//http://docs.groovy-lang.org/next/html/gapi/groovy/xml/StreamingMarkupBuilder.html
out = new groovy.xml.StreamingMarkupBuilder(encoding:'utf-8').bind{
mkp.yield xml
}
println out
println out.toString() // string
println out.class // groovy.xml.StreamingMarkupBuilder
out = new groovy.xml.StreamingMarkupBuilder(encoding:'utf-8').bind{
mkp.yieldUnescaped groovy.xml.XmlUtil.serialize(xml)
}
println out
println out.toString() // string
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment