Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

This branch is 21 commits behind touv:master

Failed to load latest commit information.
lib regular option was not initialized to true + big.js test for memory l…
test-big iseparate the big test to avoid Travis limitation
test iseparate the big test to avoid Travis limitation
.gitignore it's works
.travis.yml ci for 0.8
LICENSE
README.md add regular's option
index.js first step
package.json new release

README.md

XML Splitter for NodeJS

Build Status

It's native and full Javascript class, that provides an easy way to split huge XML datas with one or more paths.

Installation

With npm do:

$ npm install xml-splitter

Examples

Basic

    var XMLSplitter = require('xml-splitter')

    xs = new XMLSplitter('/root/item')
    xs.on('data', function(data) {
        console.log(data)
    })
    xs.on('end', function(counter) {
        console.log(counter+' slices !')
    })
    xs.parseString('<root><item><id>1</id></item><item><id>2</id></item></root>')

Output:

{ id: { '$t': '1' } }
{ id: { '$t': '2' } }
2 slices !

Multi-paths

    var XMLSplitter = require('xml-splitter')

    xs = new XMLSplitter(['/root/item', '/root/entry'])
    xs.on('data', function(data) {
        console.log(data)
    })
    xs.on('end', function(counter) {
        console.log(counter+' slices !')
    })
    xs.parseString('<root><item><id>1</id></item><entry><id>2</id></entry></root>')

Output:

{ id: { '$t': '1' } }
{ id: { '$t': '2' } }
2 slices !

Streaming

    var XMLSplitter = require('xml-splitter')

    xs = new XMLSplitter('/root/item')
    xs.on('data', function(data) {
        console.log(data)
    })
    xs.on('end', function(counter) {
        console.log(counter+' slices !')
    })
    xs.parseStream(process.stdin) // or process.stdin.pipe(xs.stream)

Tests

Use nodeunit to run the tests.

$ npm install nodeunit
$ nodeunit test

API Documentation

Methods

constructor XMLSplitter(cutter, options)

Create an new splitter, cutter is a string or an array of strings that contains path. Options are :

  • regular : To indicate if the cutter is applied to not nested XML parts. By default is true (to optimize the memory consumation)

parseString(string, encoding)

Split XML within a string

parseStream(stream)

Split XML within a stream

Events

data

Emit on each slice.

close

Emit if the stream emit the close event OR if the stream is destroyed

end

Emit on the end of the XML parsing

error

Emit when something bad happened

XPath's operators

The XPath standard is not supported, only basic paths (included namespaces) and fews operotors is implemented :

  • / : /record, /record/item
  • // : //para, /root//item
  • * : /root//item, /root/item/

I do not think I will implement more operators.

Also

License

MIT/X11

Something went wrong with that request. Please try again.