Topic
  • 2 replies
  • Latest Post - ‏2011-06-07T01:50:29Z by nobusue
nobusue
nobusue
2 Posts

Pinned topic CSV generation script from exported XML report

‏2011-05-27T08:52:19Z |
Hello,

I was asked from customer how to export migration analysis report, but I can't find such function(except "Java Code Review" table view), so I created small groovy script to transform XML report into CSV.

GenCsv.groovy



import groovy.util.XmlParser   

if (!args) 
{ println 
'Usage: groovy GenCsv.groovy <XML filename>' System.exit(0) 
}   def fileName = args[0] def root = 

new XmlParser().parse(

new File(fileName))   
// Mapping file id to path def fileIdMap = [:] root.files.file.each
{ file -> fileIdMap[file.@id.toString()] = file.@path 
} 
//println fileIdMap   
// Output CSV file 

new File(fileName + 
'.csv').withWriter
{ writer -> writer << 
'Category, Rule, Filename, Line\n' root.PROVIDER.CATEGORY.RULE.result.each
{ writer << 
"${it.'..'.'..'.@name}, ${it.'..'.@name}, ${fileIdMap[it.@fileId.toString()]}, ${it.@line?:''}\n" 
} 
}


To use this:
  • install JDK and Groovy
  • install JDK and execute "java -jar groovy-all-1.8.0.jar GenCsv.groovy <filename>"

You can get groovy-all-1.8.0.jar from Groovy-1.8.0 binary distribution under "embeddable" directory.
http://groovy.codehaus.org/
Updated on 2011-06-07T01:50:29Z at 2011-06-07T01:50:29Z by nobusue
  • SystemAdmin
    SystemAdmin
    102 Posts

    Re: CSV generation script from exported XML report

    ‏2011-06-06T17:27:13Z  
    Hi,
    Thanks for sharing this. What information was your customer interested in from the report point of view? Were they simply interested in how many rules were detected? Did they ask for any other information to be generated in the report?

    Cindy
  • nobusue
    nobusue
    2 Posts

    Re: CSV generation script from exported XML report

    ‏2011-06-07T01:50:29Z  
    Hi,
    Thanks for sharing this. What information was your customer interested in from the report point of view? Were they simply interested in how many rules were detected? Did they ask for any other information to be generated in the report?

    Cindy
    Cindy,

    My customer simply wants to extract the result in reusable form.
    We have separeted(canonicalized) filename in XML export, so I made the script to combine file ID and filename.