Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcreigno/node-xmlstream-parser
simple xml stream parser based on sax
https://github.com/jcreigno/node-xmlstream-parser
Last synced: 6 days ago
JSON representation
simple xml stream parser based on sax
- Host: GitHub
- URL: https://github.com/jcreigno/node-xmlstream-parser
- Owner: jcreigno
- License: mit
- Created: 2014-11-12T21:10:27.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-13T10:07:48.000Z (about 10 years ago)
- Last Synced: 2024-10-12T10:10:06.188Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 152 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
node-xmlstream-parser
=====================simple xml stream parser based on sax.
Takes a readable xml stream as input and emits parsed object as result.This module is inspired by [JSONStream.parse](https://github.com/dominictarr/JSONStream#jsonstreamparsepath).
### Installation
`npm install --save xmlstream-parser`
### Usage
```js
var streamParser = require('../lib/index'),
JSONStream = require('JSONStream'),
fs = require('fs');fs.createReadStream('response.xml')
.pipe(streamParser.parse('Item')) // emit Items elements
.pipe(JSONStream.stringify()) // stringify objects
.pipe(process.stdout);
```### Parsing rules
* node attributes are parsed and prefixed with `$`
```xml```
is parsed as :
```js
{
message: {
$value : 'hello'
}
}
```* if a node element as only one child text node then it is parsed as simple value
```xml
hello
```
is parsed as :
```js
{
message: 'hello'
}
```
* if a node as more than one child with the same name then it is parsed as an Array
```xml
hello
world
```
is parsed as :
```js
{
message: ['hello', 'world']
}
```* if a node as more than one child with with a text node, then it is parsed as `_`
```xml
hello
```
is parsed as :
```js
{
message: {
_ : 'hello',
$priority : 'important'
}
}
```