xml2csv
Takes an XML file and transforms it into a CSV file, based on format of the map you provide with options.
Install
$ npm install xml2csv --save
Usage
const xml2csv =
Input:
<People>
<Person>
<Name>Maggie</Name>
<Age>3</Age>
<Gender>Female</Gender>
<Siblings>
<Brother>Bart</Brother>
<Sister>Lisa</Sister>
</Siblings>
</Person>
<Person>
<Name>Marge</Name>
<Age>45</Age>
<Gender>Female</Gender>
</Person>
</People>
Output:
name, age, gender, brother, sister
"Maggie",3,"Female","Bart","Lisa"
"Marge",45,"Female",,
options
, callback
)
xml2csv(Options
Property | Type | Notes |
---|---|---|
xmlPath |
string |
A path to the xml input file. |
csvPath |
string |
The path and filename of the generated CSV output file (note that any intermediate folders will be created). |
rootXMLElement |
string |
The XML root tag for each record, element to split records on in XML file. |
headerMap |
[array] |
See the Header Map section for more details. |
options.headerMap
options.headerMap needs to be in the structure of:
[
[xmlTag, csvHeader, type, parent],
[xmlTag, csvHeader, type, parent],
...
]
- xmlTag and csvHeader must be the related fields
- type must be integer, date or string
- parent is optional, must be the parent tag in format of the XML tag
Testing
$ npm test