Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.