saxo-parser
A friendly way to configure a SAX parser
Last updated 4 years ago by nch3v .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install saxo-parser 
SYNC missed versions from official npm registry.

SaxoParser

Purpose

SaxoParser is a helper to configure a sax parser using a self descriptive configuration object.

Installation

npm i -S saxo-parser

Usage

var SaxoParser = require('saxo-parser');

var saxo = new SaxoParser({
	myTag : {
		_open: function(tag) {
			tag.data = {};
			tag.data.someProp = tag.attributes.someProp;
			tag.data.moreProps = [];
		},
		_close: function(tag) {
			// do something with tag.data
			console.log(JSON.stringify(tag.data));
		},
		mySubTag : {
			_close: function(tag) {
				tag.parent.data.moreProps.push(tag.text);
			}
		}
	}
});

saxo.parseString('<root><myTag someProp="someValue"><mySubTag>Some</mySubTag><mySubTag>Text</mySubTag></myTag></root>');

API

The constructor function takes an object describing what function should be called when parsing each xml element.

The entries of the object can be either a tag element name or a special function _open, _text or _close. None of the special method is mandatory and should be used depending of the object to be parsed.

The parser can then parse a string with parseString, an inputStream with parseStream or a file with parseFile

		'

Current Tags

  • 1.0.1                                ...           latest (4 years ago)

2 Versions

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

Copyright 2014 - 2016 © taobao.org |