88 Raver Croft Drive
Chattanooga, TN 37403
Tel: 1-423-665-9085
How to Convert XML to CSV
So, you want to convert your XML file to a different format? It is definitely possible to code your own XML parser, but why go through all the trouble?
Most programming languages already include XML libraries that can do both parsing and data validation for you. I am talking about Java or C, for example. Several scripting languages, such as Perl or Python, include XML libraries as well. And many people have built programming environments that make use of XML syntax. Here are the most popular XML-based programming languages, according to Data Alliance.
As you can see, XML is very popular, especially because it's so easy to use. All you need to do to work with this type of files is to know the structure of the XML document. That's necessary because no code snippet in the world will be able to detect the meaning of your data and its location inside the XML file, unless you provide a clear description of it.
Of course, sometimes you may have to work with an XML file that was created by somebody else. In this case, you should either contact its creator, or try to find some documentation that describes it online.
Once that you have figured out the XML structure, there are lots of applications that can map the source elements to the target fields. As with any conversion process, sometimes you may lose metadata, especially when the parser can't figure out a way to display it properly.
You can tell that I am an XML fan ;) but the reality is that CSV is just as popular - if not more popular. This explains why some people would want to convert XML to CSV.
Fortunately, there is an easy way to do that, and the data can be output in one of the many file formats that are supported by Excel.
Here's how you can do it, step by step.
1. Start Excel, and then choose Data -> Get Data -> From File -> From XML
2. The data navigator window will show up.
4. Click "Load" if everything looks OK, and then wait for a few moments, until the data is fully loaded.
5. Now that the data was imported, you can export it to any format that's supported by Excel - including PDF! Here's how to export the data to the popular CSV format.
a) Click File -> Export -> Change File Type -> CSV (Comma Delimited) (*.csv)
b) Click the "Save As" button, and then give your file a name. Press "Save" to do the job.
Excel will tell you if there may be any potential data loss with your chosen format.
CSV files don't support multiple sheets, for example, but don't let that get in the way! All your XML files should be fine, because the data is only stored in the first Excel sheet.
c) Finally, open the exported CSV file in Excel, to make sure that everything looks OK.
As you can see, it's a painless process that can save you a lot of time. Of course, some people have built dedicated applications like this one, which can do the job. In fact, some of them have additional features, such as batch XML import/export, which can't be done with Excel - at least not with the current version of the tool.