# smithereens-xml

> Practice with XML streams

Latest version **1.0.0** (published 2017-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install smithereens-xml
pnpm add smithereens-xml
yarn add smithereens-xml
bun add smithereens-xml
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-09-25 |
| First published | 2017-09-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tim Needham |
| Maintainers | meena.hoda |

## Links

- npm: https://www.npmjs.com/package/smithereens-xml
- npm.io page: https://npm.io/package/smithereens-xml

## Dependencies (3)

- [sax](https://npm.io/package/sax.md) ^1.2.4
- [dottie](https://npm.io/package/dottie.md) ^2.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4

## Recent versions

- 1.0.0 (latest) — 2017-09-25

## README

# xml2csv

> Takes an XML file and transforms it into a CSV file, based on format of the map you provide with options. 

## <a name="install"></a>Install
```bash
$ npm install xml2csv --save
```


## <a name="usage"></a>Usage

```javascript
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](#headerMap) section for more details.

### <a name="headerMap"></a>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


## <a name="test"></a>Testing


```bash
$ npm test
```


## <a name="license"></a>License
[MIT](https://github.com/wmfs/supercopy/blob/master/LICENSE)

---
_Source: https://npm.io/package/smithereens-xml · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
