Last active
June 30, 2022 06:36
-
-
Save ppazos/50826d54d47b38740c1ecc4687c9eb2b to your computer and use it in GitHub Desktop.
Examples with XML serialization in pretty print and ugly print / minified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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