Created
December 21, 2011 19:53
-
-
Save russellkt/1507427 to your computer and use it in GitHub Desktop.
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
import au.com.bytecode.opencsv.* | |
def xmlFilePattern = ~/.*\.XML/ | |
def iterator = 0 | |
def itemAttributes, contentAttributes | |
String[] checkAttributes | |
def checks = [] | |
new File('/Volumes/mac3/cleared_checks/').eachFileMatch(xmlFilePattern){ | |
def xmlFile = new XmlParser().parse(it) | |
def items = xmlFile.Item | |
if(itemAttributes == null){ | |
itemAttributes = items.ItemData[0].attributes().keySet() | |
contentAttributes = items.Content[0].attributes().keySet() | |
checkAttributes = new String[itemAttributes.size() + contentAttributes.size()] | |
itemAttributes.eachWithIndex{ att, index -> checkAttributes[index] = att } | |
contentAttributes.eachWithIndex{ att, index -> checkAttributes[index + itemAttributes.size()] = att } | |
} | |
items.eachWithIndex{ item, index -> | |
String[] check = new String[checkAttributes.size()] | |
itemValues = item.ItemData[0].attributes().collect{ k,v -> v} | |
contentValues = item.Content[0].attributes().collect{ k,v -> v} | |
check = itemValues + contentValues | |
checks << check | |
} | |
} | |
writer = new CSVWriter(new FileWriter("/Volumes/mac3/cleared_checks.csv")) | |
writer.writeNext(checkAttributes) | |
checks.each{ writer.writeNext(it)} | |
writer.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment