read-xml
Read a xml file respecting its encoding information
Last updated 2 years ago by bjrmatos .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install read-xml 
SYNC missed versions from official npm registry.

read-xml

NPM Version License Build Status

Read a xml file respecting its encoding information

Usage

simple-iso-8859-1.xml

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<test>
  <value>ácentó y la letra ñ<value>
</test>

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

<!-- output produced by fs.readFile/fs.readFileSync -->
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<test>
  <value>�cent� y la letra �<value>
</test>

Basic API

'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

'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

License

See license

Current Tags

  • 3.0.0                                ...           latest (2 years ago)
  • 1.0.0-rc1                                ...           next (4 years ago)

6 Versions

  • 3.0.0                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0-rc1                                ...           4 years ago
  • 1.0.0 [deprecated]           ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 6
Dependencies (6)

Copyright 2014 - 2016 © taobao.org |