xml2csv

command module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2020 License: MIT Imports: 14 Imported by: 0

README

xml2csv

xml2csv converts XML to CSV.
You can easily define mappings for converts using XPath.

Usage

$ xml2csv -i input.xml -m mapping.json -o output.csv

The arguments are as follows.

Usage of xml2csv:
  -b    CSV with BOM
  -h    Help
  -i string
        XML input file path or directory or url
  -m string
        XML to CSV mapping file path or url
  -o string
        CSV output file path

XML and mapping files can be specified by URL.

xml2csv -i https://github.com/onozaty/xml2csv/raw/master/testdata/rss.xml -m https://github.com/onozaty/xml2csv/raw/master/mapping/rss.json -o output.csv

Mapping

The conversion mapping definition is written in JSON.
Specify the position on the XML with XPath.

{
    "rowsPath": "//item",
    "columns": [
        {
            "header": "title",
            "valuePath": "/title"
        },
        {
            "header": "link",
            "valuePath": "/link"
        },
        {
            "header": "description",
            "valuePath": "/description"
        }
    ]
}
  • rowsPath : XPath to get as a rows.
  • columns : Definition of each column.
    • header : CSV header.
    • valuePath : XPath to get as a value.
    • useEvaluate : Specify true when using an expression with valuePath. For example, when using sum() or not(), boolean().

Please refer to the sample below.

Install

You can download the binary from the following.

License

MIT

Author

onozaty

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL