Skip to content

ziluvatar/node-xml-buffer-tostring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XML Buffer To String

Build Status codecov

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. 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, 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 file.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published