New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

read-xml

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-xml

Read a xml file respecting its encoding information

latest
Source
npmnpm
Version
3.0.0
Version published
Weekly downloads
212
19.1%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

xml

FAQs

Package last updated on 07 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts