Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wmfs/xml2csv

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wmfs/xml2csv

Convert XML file to CSV file

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

xml2csv

Tymly Package npm (scoped) Build Status codecov CodeFactor Dependabot badge Commitizen friendly JavaScript Style Guide license

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', 'integer'],
      ['Gender', 'gender', 'string'],
      ['Brother', 'brother', 'string', 'Siblings'],
      ['Sister', 'sister', 'string', 'Siblings']
    ]
  },
  function (err, info) {
    console.log(err, info)
    // Done!
  }
)

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",,

xml2csv(options, callback)

Options

PropertyTypeNotes
xmlPathstringA path to the xml input file.
csvPathstringThe path and filename of the generated CSV output file (note that any intermediate folders will be created).
rootXMLElementstringThe 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

FAQs

Package last updated on 11 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc