Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Write XML into a file without whitespace character in Groovy
import groovy.xml.MarkupBuilder
* Produces xml file that has no whitespace character.
* new IndentPrinter(out, "", false) section does all things we need to do.
* Example output:
* <products><product><title>product title</title><price>100</price></product></products>
def writeXMLWithoutWhitespaces(String filePath) {
new File(filePath).withWriter { out ->
MarkupBuilder xml = new MarkupBuilder(new IndentPrinter(out, "", false))
xml.products {
product {
title("product title")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment