Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

smithereens-xml

1.0.0 • Public • Published

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 = require('xml2csv')
 
xml2csv(
  {
    xmlPath: 'path/to/file.xml',
    csvPath: 'path/to/file.csv',
    rootXMLElement: 'Record',
    headerMap: [
      ['Name', 'name', 'string'],
      ['Age', 'age', 'string'],
      ['Gender', 'gender', 'string'],
      ['Brother', 'brother', 'string', 'Siblings'],
      ['Sister', 'sister', 'string', 'Siblings']
    ]
  },
  function (err, info) {
    console.log(err, info)
    // Done!
  }
)
 

xml2csv(options, callback)

Options

Property Type Notes
xmlPath string A path to the xml input file.
csvPath string A path to the csv output file.
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

License

MIT

Keywords

none

Install

npm i smithereens-xml

DownloadsWeekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar