# xml-buffer-tostring

> The library converts a buffer containing a XML serialized to a string, detecting the proper encoding

Latest version **0.2.0** (published 2017-10-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install xml-buffer-tostring
pnpm add xml-buffer-tostring
yarn add xml-buffer-tostring
bun add xml-buffer-tostring
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2017-10-19 |
| First published | 2017-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Eduardo Díaz |
| Maintainers | ziluvatar |
| Keywords | xml, encoding, prolog, bom, buffer, decode |

## Links

- npm: https://www.npmjs.com/package/xml-buffer-tostring
- Repository: https://github.com/ziluvatar/node-xml-buffer-tostring
- Homepage: https://github.com/ziluvatar/node-xml-buffer-tostring#readme
- Issues: https://github.com/ziluvatar/node-xml-buffer-tostring/issues
- npm.io page: https://npm.io/package/xml-buffer-tostring

## Dependencies (1)

- [iconv-lite](https://npm.io/package/iconv-lite.md) ^0.4.19

## 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.2.0 (latest) — 2017-10-19

## README

XML Buffer To String
--------------------
[![Build Status](https://circleci.com/gh/ziluvatar/node-xml-buffer-tostring/tree/master.svg?style=shield)](https://circleci.com/gh/ziluvatar/node-xml-buffer-tostring/tree/master.svg?style=shield)
[![codecov](https://codecov.io/gh/ziluvatar/node-xml-buffer-tostring/branch/master/graph/badge.svg)](https://codecov.io/gh/ziluvatar/node-xml-buffer-tostring)

This library will convert a XML from a buffer to a string, dealing with the different encodings that can be used when serializing a XML.

Currently it fully supports UTF-8, UTF-16 and the ISO-8859 family.

# Installation

`npm i xml-buffer-tostring`

# Usage

The library exports a function that can be used for the conversion:

```
const xmlBufferToString = require('xml-buffer-tostring');
const xmlString = xmlBufferToString(buffer);
```

### Default encoding

When it is not possible to extract the encoding then the default encoding is used.

You can pass a default encoding using the options parameter. Since this library uses `iconv-lite` internally you can choose one from [their supported encodings](https://github.com/ashtuchkin/iconv-lite/wiki/Supported-Encodings). When no default encoding is passed `utf8` is used.

```
const xmlBufferToString = require('xml-buffer-tostring');
const xmlString = xmlBufferToString(buffer, { defaultEncoding: 'ISO-8859-1' });
```

# Encoding detection details

Although the library uses encoding detection with and without BOM following the indications of the [specification](https://www.w3.org/TR/xml/#sec-guessing), it is not strict with the failures, instead it uses precedence.

If an encoding attribute is found on the xml declaration it will use that as encoding, otherwise the detected encoding (from BOM or `<?` chars) would be used.


# License

The MIT License. See [LICENSE](LICENSE) file.

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