Skip to content

Instantly share code, notes, and snippets.

@jurberg
Created November 11, 2012 20:07
Show Gist options
  • Save jurberg/4056079 to your computer and use it in GitHub Desktop.
Save jurberg/4056079 to your computer and use it in GitHub Desktop.
Convert XML to Flat File
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