Created
February 7, 2016 17:11
-
-
Save baybatu/3070e63c5ae83a1c3d75 to your computer and use it in GitHub Desktop.
Write XML into a file without whitespace character in Groovy
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
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