# easyxml

> A configurable object to XML converter

Latest version **2.0.1** (published 2016-02-05) · (BSD-3-Clause OR GPL-2.0) license · 0 weekly downloads

## Install

```sh
npm install easyxml
pnpm add easyxml
yarn add easyxml
bun add easyxml
```

## 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 | 2.0.1 |
| Published | 2016-02-05 |
| First published | 2012-10-25 |
| Weekly downloads | 0 |
| License | (BSD-3-Clause OR GPL-2.0) |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Thomas Hunter II |
| Maintainers | tlhunter |
| Keywords | xml, json |

## Links

- npm: https://www.npmjs.com/package/easyxml
- Repository: https://github.com/tlhunter/node-easyxml
- Homepage: https://github.com/tlhunter/node-easyxml#readme
- Issues: https://github.com/tlhunter/node-easyxml/issues
- npm.io page: https://npm.io/package/easyxml

## Dependencies (2)

- [inflect](https://npm.io/package/inflect.md) ^0.3.0
- [elementtree](https://npm.io/package/elementtree.md) ^0.1.6

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.1 (latest) — 2016-02-05
- 2.0.0 — 2016-02-05
- 1.1.2 — 2016-02-05
- 1.1.0 — 2016-02-05
- 1.0.0 — 2014-12-20
- 0.2.0 — 2014-12-20
- 0.1.0 — 2014-12-20
- 0.0.6 — 2014-12-20
- 0.0.5 — 2013-12-11
- 0.0.4 — 2013-02-21
- 0.0.3 — 2013-01-24
- 0.0.2 — 2012-10-25
- 0.0.1 — 2012-10-25

## README

# Easy XML

Highly configurable Object to XML converter for Node.

## Installation

```console
$ npm install easyxml
```

## Usage

```javascript
var EasyXml = require('easyxml');

var serializer = new EasyXml({
    singularize: true,
    rootElement: 'response',
    dateFormat: 'ISO',
    manifest: true
});

var obj = {
    items: [{
        name: 'one',
        _id: 1
    }, {
        name: 'two',
        _id: 2
    }, {
        name: 'three',
        _id: 3
    }],
    blah: 'http://www.google.com',
    when: new Date(),
    boolz: true,
    nullz: null
};

console.log(serializer.render(obj));
```

This should output the following XML document:

```xml
<?xml version='1.0' encoding='utf-8'?>
<response>
  <items>
    <item id="1">
      <name>one</name>
    </item>
    <item id="2">
      <name>two</name>
    </item>
    <item id="3">
      <name>three</name>
    </item>
  </items>
  <blah>http://www.google.com</blah>
  <when>2012-09-25T18:47:39.485Z</when>
  <boolz>true</boolz>
  <nullz />
</response>
```

## Configuration

| Config Setting            | Purpose                                                           | Default   |
|---------------------------|-------------------------------------------------------------------|-----------|
| attributePrefix           | JSON with this prefix will be XML attributes instead of elements  | '\_'      |
| dateFormat                | A date format for JS dates, currently accepts ISO, SQL, JS        | 'ISO'     |
| filterNulls               | Should nulls and undefines be removed from the rendered XML       | false     |
| indent                    | The number of spaces to indent child elements with                | 2         |
| manifest                  | Whether or not to add that XML manifest line to the top           | false     |
| rootArray                 | If the root element is an array, this wraps the XML document      | 'items'   |
| rootElement               | A string to wrap around the rendered XML document                 | 'response'|
| singularize               | If an array is plural, its children elements will be singular     | true      |
| unwrapArrays              | If true will keep array children at parents level                 | false     |


## Migration Guide from 1.x to 2.x

* `singularizeChildren` has been renamed `singularize`
* `allowAttributes` has been removed since it was redundant
* `unwrappedArrays` has been renamed `unwrapArrays`
* **Behavior**: XML documents now default to 2 spaces instead of 4
* **Behavior**: Objects with `.toJSON()` methods now have that method executed
* **Behavior**: When using singularize with a pluralized array of objects they now no longer accidentally nest


## License

This project is dually licensed under the BSD-3-Clause / GPL-2.0 licenses.

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