Skip to content

Instantly share code, notes, and snippets.

@coderberry
Created October 7, 2010 22:21
Show Gist options
  • Select an option

  • Save coderberry/616027 to your computer and use it in GitHub Desktop.

Select an option

Save coderberry/616027 to your computer and use it in GitHub Desktop.
class CommonTagLib {
static namespace = 'berry'
def formatXML = { attrs, body ->
String rawXML = body().toString()
try {
def slurpedXML = new XmlSlurper().parseText(rawXML)
def writer = new StringWriter()
new XmlNodePrinter(new PrintWriter(writer)).print(slurpedXML)
def formattedResponse = writer.toString()
out << formattedResponse
} catch(Exception e) {
log.info "Unable to parse XML: ${e.message}"
out << rawXML
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment