Skip to content

Instantly share code, notes, and snippets.

@baybatu
Created February 7, 2016 17:11
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 baybatu/3070e63c5ae83a1c3d75 to your computer and use it in GitHub Desktop.
Save baybatu/3070e63c5ae83a1c3d75 to your computer and use it in GitHub Desktop.
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")
price("100")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment