# xmlserializer

> Serializes a document to XML/XHTML

Latest version **0.6.1** (published 2018-01-04) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.1 |
| Published | 2018-01-04 |
| First published | 2013-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/xmlserializer) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 37 |
| Author | Christoph Burgmer |
| Maintainers | cburgmer |
| Keywords | html, html5, xhtml, xml, serializer, XMLSerializer |

## Links

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

## 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

- 0.6.1 (latest) — 2018-01-04
- 0.6.0 — 2016-11-05
- 0.5.0 — 2016-11-05
- 0.4.0 — 2016-07-02
- 0.3.3 — 2014-09-29
- 0.3.2 — 2014-09-27
- 0.3.1 — 2014-04-01
- 0.3.0 — 2013-11-20
- 0.2.0 — 2013-11-14

## README

xmlserializer serializes a DOM subtree or DOM document into XML/XHTML.
<a href="https://www.npmjs.org/package/xmlserializer">
    <img src="https://badge.fury.io/js/xmlserializer.svg"
         align="right" alt="NPM version" />
</a>

It understands documents generated by [parse5](https://github.com/inikulin/parse5) and regular browser DOMs (and thus can act as a drop-in replacement for [XMLSerializer](https://developer.mozilla.org/en/docs/XMLSerializer) which for some browsers only serializes true XML documents).

Limitations
-----------

See [the wiki](https://github.com/cburgmer/xmlserializer/wiki) for limitations in HTML to XML conversion.

Currently some cases are treated differently to the XMLSerializer implementation of the browsers:

- Invalid characters (ASCII control characters) that are invalid in XML 1.0 are removed on serialization. The browsers silently include those characters and on reparsing those documents throw a parser exception.
- Dashes in comments are escaped to provide valid comments in XHTML. Firefox does not do this.
- The `xmlns` attribute has higher precedence than the type of the DOM object passed to the serializer.
- Small differences in style: no space in self-closing tag, empty value for boolean attributes, quoting of single apostrophes in attribute values.

This behaviour might become optional in the future.

Demo
----

See https://runkit.com/embed/siinwcyjdcjw

Run tests and build for the browser
-----------------------------------

    $ npm install && npm test

[![Build Status](https://travis-ci.org/cburgmer/xmlserializer.svg?branch=master)](https://travis-ci.org/cburgmer/xmlserializer)

Example
-------

For a browser based example run `npm test` and see `example.html`.

The same code for Node.js:

```js
var xmlserializer = require('xmlserializer');
var html2xhtml = function (htmlString) {
    var parser = require('parse5'),
        dom = parser.parse(htmlString);

    return xmlserializer.serializeToString(dom);
};
console.log(html2xhtml('<br>'));
// => <html xmlns="http://www.w3.org/1999/xhtml"><head/><body><br/></body></html>
```

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