# @vates/xml

> Simple XML formatting/parsing

Latest version **2.0.0** (published 2024-04-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install @vates/xml
pnpm add @vates/xml
yarn add @vates/xml
bun add @vates/xml
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2024-04-30 |
| First published | 2024-04-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 987 |
| Author | Vates SAS |
| Maintainers | mlssfrncjrg, b-nollet, arnogues, florent.beauchamp, mathieura, enishowk, tgoettelmann, julien-f, marsaud, olivierlambert, pdonias |

## Links

- npm: https://www.npmjs.com/package/@vates/xml
- Repository: https://github.com/vatesfr/xen-orchestra
- Homepage: https://github.com/vatesfr/xen-orchestra/tree/master/@vates/xml
- Issues: https://github.com/vatesfr/xen-orchestra/issues
- npm.io page: https://npm.io/package/@vates/xml

## Dependencies (1)

- [sax](https://npm.io/package/sax.md) ^1.3.0

## Recent versions

- 2.0.0 (latest) — 2024-04-30

## README

<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->

# @vates/xml

[![Package Version](https://badgen.net/npm/v/@vates/xml)](https://npmjs.org/package/@vates/xml) ![License](https://badgen.net/npm/license/@vates/xml) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/xml)](https://bundlephobia.com/result?p=@vates/xml) [![Node compatibility](https://badgen.net/npm/node/@vates/xml)](https://npmjs.org/package/@vates/xml)

> Simple XML formatting/parsing

## Install

Installation of the [npm package](https://npmjs.org/package/@vates/xml):

```sh
npm install --save @vates/xml
```

## Usage

### `parseXml(xml, [opts])`

> Based on [`sax`](https://www.npmjs.com/package/sax)

`opts` is an optional object which can contain the following options:

- `normalize = true`: if true, then turn any whitespace into a single space
- `strict = true`: whether or not to be a jerk
- `trim = true`: whether or not to trim text nodes

```js
import { parseXml } from '@xen-orchestra/xml/parse'

const tree = parseXml(`<?xml version="1.0" encoding="UTF-8"?>
<tag1 attr1="value1" attr2="value2">
  Text &amp; entities
  <tag2 />
  <tag2 />
  <ns:tag3 />
</tag1>
`)
// → {
//   name: 'tag1',
//   attributes: { attr1: 'value1', attr2: 'value2' },
//   children: [
//     'Text & entities',
//     { name: 'tag2', attributes: {}, children: [] },
//     { name: 'tag2', attributes: {}, children: [] },
//     { name: 'ns:tag3', attributes: {}, children: [] }
//   ]
// }
```

### `formatXml(tree, [opts])`

`opts` is an optional object which can contain the following options:

- `includeDeclaration = true`: whether to include an XML declaration
- `indent = 2`: string or number of spaces to use to indent; if an empty string or `0`, no indent or new lines will be used

```js
import { formatXml } from '@xen-orchestra/xml/format'

formatXml({
  name: 'tag1',
  attributes: { attr1: 'value1', attr2: 'value2' },
  children: ['Text & entities', { name: 'tag2' }, { name: 'tag2' }, { name: 'ns:tag3' }],
})
// → <?xml version="1.0" encoding="UTF-8"?>
// <tag1 attr1="value1" attr2="value2">
//   Text &amp; entities
//   <tag2 />
//   <tag2 />
//   <ns:tag3 />
// </tag1>
```

## Contributions

Contributions are _very_ welcomed, either on the documentation or on
the code.

You may:

- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
  you've encountered;
- fork and create a pull request.

## License

[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)

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