Coder Social home page Coder Social logo

saxo-parser's Introduction

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 (matches both text and cdata nodes) 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

saxo-parser's People

Contributors

nch3v avatar

Watchers

 avatar  avatar

Forkers

bittlerr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.