Created
November 11, 2012 20:07
-
-
Save jurberg/4056079 to your computer and use it in GitHub Desktop.
Convert XML to Flat File
This file contains hidden or 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 xmlToFlatFile(xml, tag, mapping) { | |
def flatFile = new StringBuffer() | |
xml[tag].each { row -> | |
mapping.each { col -> | |
col.closure.delegate = [(tag): row] | |
def result = col.closure() ?: '' | |
flatFile << result | |
.trim() | |
.padRight(col.length) | |
.substring(0, col.length) | |
} | |
flatFile << System.getProperty('line.separator') | |
} | |
flatFile.toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment