csv2xmlcmd - CSV to XML Converter¶
Description¶
Use this command line tool to convert CSV files to XML format
Usage¶
csv2xmlcmd [-h] [-i] [-o] [-e] [-N] [-c] [-P] [-d] [-T] [-f] [-t] [-r] [-ex] [-l] [-V]
Optional Arguments¶
Arguments available via the --help
flag:
-h, --help show this help messag and exit, also /? and -?
-i, --infile JSON input - file, URL, or stdin
-o, --outfile Output file, console if not specified
-e, --encoding Set the encoding type.
-ho, --headover Override CSV header with comma separated heading
-N, --noheader No heading in CSV input file
-c, --config Config filename to load and use.
-P, --pretty Pretty format output
-d, --delimiter Delimiter of csv input, use -T for tab
-T, --tab Tab is input delimiter. Overrides -d
-f, --fields Fields to include, starting at 1, ex. 3,2,1
-t, --topname Name of top XML element, default root
-r, --rowname Name of repeating row element, default row
-ex, --exclude Fields to exclude, starting at 1, ex. 3-5
-l, --limit Limit total lines written to output.
-nf, --nulls Fields to convert "null" string to empty value. Default is all fields
-nx, --exnulls Fields to not convert "null" string to empty value
-V, --verbose Output helpful messages
-i –infile¶
You must pass the tool either a file path, or a 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 .json file that is saved in the c:data folder. In the second example, we are loading directly from an example
website URL:
csv2xmlcmd -i c:\data\example.csv
csv2xmlcmd -i http://www.example.com/example.csv`
-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:
csv2xmlcmd -i c:\example.csv -o c:\converted.xml
csv2xmlcmd -i http://www.example.com/example.csv -o c:\converted.xml
-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.
By default the encoding will be determined for you.
csv2xmlcmd -i c:\data\example.csv -e utf-8
csv2xmlcmd -i c:\data\example.csv --encoding utf-16
csv2xmlcmd -i c:\data\example.csv
-N –noheader¶
Pass this to indicate the input CSV file has no column headings. The default value is to assume headers are in the input file.
csv2xmlcmd -i c:\example.csv -o c:\converted.xml -N
-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:
csv2xmlcmd -i c:\example.csv -o c:\myoutput.xml -c c:\myconfig.txt
-P –pretty¶
The -P
or --pretty
flag will format the output into a pretty format:
csv2xmlcmd -i c:\example.csv -P
-d –delimiter¶
The -D
or --delimiter
flag will allow the user to pass the type of delimiter in the CSV file.
If not passed, then the delimiter will be determined for you.:
csv2xmlcmd -i c:\example.csv -d '-'
In order to pass Tab as the delimiter, use -T as the parameter to override the delimiter:
csv2xmlcmd -i c:\example.csv -T
-f –fields¶
The -f
or --fields
flag allows you to specifically set which field columns to include:
csv2xmlcmd -i c:\example.csv -f 3,2,1
-ex –exclude¶
The -ex
or --exclude
flag allows you to specifically set which field columns to exclude:
csv2xmlcmd -i c:\example.csv" -ex 3-5
-t –topname¶
The -t
or --topname
flag sets the name of top XML element. The default is root:
csv2xmlcmd -i c:\example.csv" -t basic
-r –rowname¶
The -r
or --rowname
flag sets the name of repeating row element. The default is row:
csv2xmlcmd -i c:\example.csv" -r fieldname
-l –limit¶
The -l
or --limit
flag will limit the number of rows used in 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.
csv2xmlcmd -i c:\example.csv -l 10
-V –verbose¶
The -V
or --verbose
flag will output useful messages as the program runs:
csv2xmlcmd -i c:\example.csv -V