xml2csvcmd - XML to CSV Converter

Description

Use this command line tool to convert XML files to CSV format

Usage

xml2csvcmd [-h] [-i] [-o] [-e] [-d] [-l] [-k] [-N] [-U] [-S] [-c] [-X]

Optional Arguments

Arguments available via the --help flag:

-h, --help        show this help message and exit
-i , --infile     XML file or URL to convert.
-o , --outfile    CSV file to be written
-e , --encoding   Set the encoding type.
-d, --dump        Dump Config settings to file.
-l , --limit      Limit total lines written to CSV.
-k , --key        Key value of target array in file.
-N, --noheading   Skip the headers.
-U, --uselargest  Use largest array.
-S, --suppress    Suppress line breaks.
-c , --config     Config filename to load and use.
-X, --xlsx        Export CSV to Excel(xlsx).

-h –help

View help or available parameters using --help:

xml2csvcmd --help

-i –infile

You must pass the tool either a file path or web url and you must use the -i or --infile parameter followed by the input as shown in the below. In the first example, we are loading a .xml file that is saved in the c:data folder. In the second example, we are loading directly from an example website URL:

xml2csvcmd -i c:\data\example.xml
xml2csvcmd -i http://www.example.com/example.xml`

-o –outfile

The -o or --outfile parameter sets the file in which to save the converted results. If no parameter is set, then the output is written to the screen:

xml2csvcmd -i c:\data\example.xml -o c:\output\converted.csv

xml2csvcmd -i http://www.example.com/example.xml  -o converted.csv

-e –encoding

In order to specify an encoding type for the file, pass the -e or --encoding parameter. The most common encoding types are UTF-8 and UTF-16. The default for this parameter is UTF-8 if there is none set.

xml2csvcmd -i c:\example.xml -e utf-8

xml2csvcmd -i c:\example.xml --encoding utf-16

-d –dump

The -d or --dump parameter essentially tells the converter to save the configuration file used in the conversion. The configuration file can be exported every time a conversion is performed. There is always a default configuration:

xml2csvcmd -i c:\example.xml -o c:\converted.csv -d

xml2csvcmd -i http://www.example.com/example.xml  -o c:\converted.csv --dump

-l –limit

The -l or --limit flag will limit the number of rows written to the CSV file. If no parameter is passed, the converter will write the entire file. This value must be a number. This parameter will not affect the headers.

xml2csvcmd -i c:\example.xml -o c:\converted.csv -l 50

xml2csvcmd -i c:\example.xml -o c:\converted.csv --limit 10

-k –key

The -k or --key flag set the key value of the repeating group in your input.:

xml2csvcmd -i c:\example.xml -k arraytgt

-N –noheading

Do not output column heading in output file. The default value is to output column headings.

xml2csvcmd -i c:\example.xml -o c:\converted.csv -N

-U –uselargest

There are some xml data formats that are multilayered, and the first value set may not be the intended set to convert. The -U or --uselargest parameter will tell the converter to focus on whichever parameter set repeats the most amount of times (and is therefore the largest, and likely target of conversion):

xml2csvcmd -i c:\example.xml -o c:\converted.csv -U

xml2csvcmd -i c:\example.xml -o c:\converted.csv --uselargest

-S –suppress

This parameter will suppress line breaks from the data. More technically, it will remove any carriage returns and line feeds from the data. The default is to allow line breaks:

xml2csvcmd -i c:\example.xml -o c:\converted.csv -S

xml2csvcmd -i c:\example.xml -o c:\converted.csv --suppress

-c –config

The configuration file used in the conversion is either created at runtime, or passed to the converter before the conversion begins. The -c or --config flag will load a configuration file to used if a path is passed:

xml2csvcmd -i c:\example.xml -o c:\myoutput.cav -c c:\myconfig.txt

-X –xlsx

This flag will allow the user to export to Excel (.xlsx) instead of to CSV.

xml2csvcmd -i c:\example.xml -X