Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bjrmatos/read-xml
Read a xml file respecting its encoding information
https://github.com/bjrmatos/read-xml
encoding read-xml xml
Last synced: about 1 month ago
JSON representation
Read a xml file respecting its encoding information
- Host: GitHub
- URL: https://github.com/bjrmatos/read-xml
- Owner: bjrmatos
- License: mit
- Created: 2016-02-09T02:52:17.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-07T15:19:05.000Z (over 6 years ago)
- Last Synced: 2024-10-12T18:08:24.474Z (3 months ago)
- Topics: encoding, read-xml, xml
- Language: JavaScript
- Homepage:
- Size: 99.6 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# read-xml
[![NPM Version](http://img.shields.io/npm/v/read-xml.svg?style=flat-square)](https://npmjs.com/package/read-xml)
[![License](http://img.shields.io/npm/l/read-xml.svg?style=flat-square)](http://opensource.org/licenses/MIT)
[![Build Status](https://travis-ci.org/bjrmatos/read-xml.png?branch=master)](https://travis-ci.org/bjrmatos/read-xml)> **Read a xml file respecting its encoding information**
## Usage
simple-iso-8859-1.xml
```xmlácentó y la letra ñ
```
Without this module the above xml file would be read incorrectly by the standard `fs` module, because node.js [only supports some encodings in its core](https://nodejs.org/dist/latest-v4.x/docs/api/buffer.html#buffer_buffer)
```xml
�cent� y la letra �
```
### Basic API
```js
'use strict';var fs = require('fs'),
path = require('path'),
xmlReader = require('read-xml');var FILE = path.join(__dirname, 'test/xml/simple-iso-8859-1.xml');
// pass a buffer or a path to a xml file
xmlReader.readXML(fs.readFileSync(FILE), function(err, data) {
if (err) {
console.error(err);
}console.log('xml encoding:', data.encoding);
console.log('Decoded xml:', data.content);
});
```### Streaming API
```js
'use strict';var fs = require('fs'),
path = require('path'),
xmlReader = require('read-xml');var FILE = path.join(__dirname, 'test/xml/simple-iso-8859-1.xml');
var decodedXMLStream = fs.createReadStream(FILE).pipe(xmlReader.createStream());
decodedXMLStream.on('encodingDetected', function(encoding) {
console.log('Encoding:', encoding);
});decodedXMLStream.on('data', function(xmlStr) {
console.log(xmlStr);
});
```## Supported encodings
All [encodings supported by iconv-lite](https://github.com/ashtuchkin/iconv-lite#supported-encodings)
## License
See [license](https://github.com/bjrmatos/read-xml/blob/master/LICENSE)