xmlstream2
Pipeable XML parser
Last updated 5 years ago by ramitos .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install xmlstream2 
SYNC missed versions from official npm registry.

xmlstream2

Pipeable XML parser

Cousin of jsonstream2 and inspired by xml-stream

install

npm install [--save/--save-dev] xmlstream2

example

<?xml version="1.0"?>
<myscript>
  <sql>
    <query error="fast" conn="conn1" stmt="stmt1">
      <success></success>
    </query>
    <fetch block="all" desc="on" stmt="stmt1">
      <row>
        <data desc="id">74</data>
        <data desc="name">sramos</data>
      </row>
      <success>+++ success stmt1</success>
    </fetch>
    <free>
      <success>+++ success </success>
    </free>
  </sql>
</myscript>
var XMLStream = require('xmlstream2');
var through = require('through2');
var writable = require('writable');
var fs = require('fs');


var rs = fs.createReadStream('./ex.xml');
rs.pipe(XMLStream('myscript.sql.fetch.row'))
.pipe(through.obj(function(row, enc, fn) {
  console.log(JSON.stringify(row, null, 2));
  fn();
}))
.pipe(writable({
  objectMode: true
}, function(chunk, enc, fn) {
  fn();
}));
{
  "_attributes": {},
  "_isSelfClosing": false,
  "_name": "row",
  "data": [
    {
      "_value": "74",
      "_attributes": {
        "desc": "id"
      },
      "_isSelfClosing": false,
      "_name": "data"
    },
    {
      "_value": "sramos",
      "_attributes": {
        "desc": "name"
      },
      "_isSelfClosing": false,
      "_name": "data"
    }
  ]
}

license

MIT

Current Tags

  • 1.1.1                                ...           latest (5 years ago)

4 Versions

  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (10)
Dev Dependencies (2)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |