CPI provides XML to CSV Converter which is documented here.
If you need to process XML, pick fields, do some further processing in a single step you can use this script. It doesn't escape "," be careful if your input can contain comma, and in general this is an error-prone way to generate CSV.
You should also check Convert XML to CSV (Apache Commons CSV)
This example also contains a class with main method. It is an idea to enable running the script on your computer with regular IDEs.