# w3c-xmlserializer

> A per-spec XML serializer implementation

Latest version **5.0.0** (published 2023-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install w3c-xmlserializer
pnpm add w3c-xmlserializer
yarn add w3c-xmlserializer
bun add w3c-xmlserializer
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2023-11-12 |
| First published | 2018-07-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/w3c-xmlserializer) |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Maintainers | timothygu, domenic, sebmaster, zirro, tmpvar, joris-van-der-wel |
| Keywords | dom, w3c, xml, xmlserializer |

## Links

- npm: https://www.npmjs.com/package/w3c-xmlserializer
- Repository: https://github.com/jsdom/w3c-xmlserializer
- Homepage: https://github.com/jsdom/w3c-xmlserializer#readme
- Issues: https://github.com/jsdom/w3c-xmlserializer/issues
- npm.io page: https://npm.io/package/w3c-xmlserializer

## Dependencies (1)

- [xml-name-validator](https://npm.io/package/xml-name-validator.md) ^5.0.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2023-11-12
- 4.0.0 — 2022-11-20
- 3.0.0 — 2021-09-18
- 2.0.0 — 2020-01-02
- 1.1.2 — 2019-03-25
- 1.1.1 — 2019-03-25
- 1.1.0 — 2019-03-25
- 1.0.1 — 2018-12-11
- 1.0.0 — 2018-10-08
- 0.0.4-0 — 2018-08-18
- 0.0.3 — 2018-08-07
- 0.0.2 — 2018-08-07
- 0.0.1 — 2018-07-01

## README

# w3c-xmlserializer

An XML serializer that follows the [W3C specification](https://w3c.github.io/DOM-Parsing/).

This package can be used in Node.js, as long as you feed it a DOM node, e.g. one produced by [jsdom](https://github.com/jsdom/jsdom).

## Basic usage

Assume you have a DOM tree rooted at a node `node`. In Node.js, you could create this using [jsdom](https://github.com/jsdom/jsdom) as follows:

```js
const { JSDOM } = require("jsdom");

const { document } = new JSDOM().window;
const node = document.createElement("akomaNtoso");
```

Then, you use this package as follows:


```js
const serialize = require("w3c-xmlserializer");

console.log(serialize(node));
// => '<akomantoso xmlns="http://www.w3.org/1999/xhtml"></akomantoso>'
```

## `requireWellFormed` option

By default the input DOM tree is not required to be "well-formed"; any given input will serialize to some output string. You can instead require well-formedness via

```js
serialize(node, { requireWellFormed: true });
```

which will cause `Error`s to be thrown when non-well-formed constructs are encountered. [Per the spec](https://w3c.github.io/DOM-Parsing/#dfn-require-well-formed), this largely is about imposing constraints on the names of elements, attributes, etc.

As a point of reference, on the web platform:

* The [`innerHTML` getter](https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml) uses the require-well-formed mode, i.e. trying to get the `innerHTML` of non-well-formed subtrees will throw.
* The [`xhr.send()` method](https://xhr.spec.whatwg.org/#the-send()-method) does not require well-formedness, i.e. sending non-well-formed `Document`s will serialize and send them anyway.

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