How to use node-expat - 10 common examples

To help you get started, we’ve selected a few node-expat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shimondoodkin / node-wurfl / index.js View on Github external
inflow.each({},devices,function(device,key)
  {
   next=this;
   //change the structure from arrays to objects
   if(device.group===undefined)
   {
    // fallback devices do not contain group
    //console.log(require('sys').inspect(device,true,3));
   }
   else
   {
    for(var n=0,l=device.group.length;n
github shimondoodkin / node-wurfl / index.js View on Github external
{
   next=this;
   //change the structure from arrays to objects
   if(device.group===undefined)
   {
    // fallback devices do not contain group
    //console.log(require('sys').inspect(device,true,3));
   }
   else
   {
    for(var n=0,l=device.group.length;n
github vchatterji / opml2json / parser.js View on Github external
{	
	//Check if input file exists
	try {
		// Query the entry
		var stats = fs.lstatSync(inputFile);

		// Is it a directory?
		if (stats.isDirectory()) {
			console.log("The specified path:" + inputFile + " is a directory not file.");
		}
		else
		{
			var tree;
			var currentNode;
			
			parser = expat.createParser();
			parser.on('startElement', function (name, attrs) {
				if(name=="outline") {
					if(tree === undefined) {
						tree = {
							parent:null,
							text: attrs.text,
							children: []
						};
						currentNode = tree;
					}
					else {
						var node = {
							parent:currentNode,
							text: attrs.text,
							children: []
						};
github shimondoodkin / node-wurfl / index.js View on Github external
function complete(error,response,data)
  {
   var parser=new expat.parser(); // new instance of parser
   //console.log(profileurl);
   //console.log(data); 
   parser.parse(data);
   var specs=parser.root;
   
   if(specs.RDF)
   {
    // array to object implementation:
    if(!(specs.RDF instanceof Array)&&specs.RDF.Description)
    {
     specs.RDF=[specs.RDF.Description];
    }
     
    
    for(var n=0,j=specs.RDF.length;n
github msiebuhr / charcod.es / ucd-xml2json.js View on Github external
var args = argparse.argv;

// {{{ fixedFromCharCode(codePoint)
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/fromCharCode
function fixedFromCharCode (codePt) {
    if (codePt > 0xFFFF) {
        codePt -= 0x10000;
        return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
    } else {
        return String.fromCharCode(codePt);
    }
}
// }}}

// Parse XML
var parser = new expat.Parser("UTF-8"),
    output = args.output ? fs.createWriteStream(args.output) : process.stdout,
    input = args.input ? fs.createReadStream(args.input) : process.stdin,
    jsonStream = JSONStream.stringifyObject("{", ",\n", "}\n");

jsonStream.pipe(output);

// Parse!
var currentChar = {};
parser.on('startElement', function (name, attrs) {
    if (name === 'char' && attrs.cp) {
        currentChar = {
            code: parseInt(attrs.cp, 16), // Codepoint
            name: attrs.na.toLowerCase(), // Name
            block: attrs.blk.toLowerCase(), // Block
        }
    } else if (name === 'name-alias') {
github sogko / node-osm-stream / lib / node-osm-stream.js View on Github external
function OSMStream(options) {
  if (!(this instanceof OSMStream)) return new OSMStream(options);

  Transform.call(this, options);

  var primaryElements = ['node', 'way', 'relation']; // emit-ables
  var subElementName = ['tag', 'nd', 'member'];

  // size of bytes read from source so far
  this.bytesRead = 0;
  // size of bytes written to stream so far
  this.bytesWritten = 0;

  // initialize parser and its event handlers
  this._parser = new expat.Parser();

  this._parser.on('pipe', (function onParserPipe(src) {
    logger('_parser received pipe from ', src.path || '');
  }).bind(this));

  this._parser.on('startElement', (function onParserStartElement(name, attrs) {
    var funcname = ['__parse_', name].join('');
    if ((primaryElements.indexOf(name) > -1 && (OSMStream.prototype[funcname])) ||
      (subElementName.indexOf(name) > -1 && this._currentElement !== null && (OSMStream.prototype[funcname]))) {
      OSMStream.prototype[funcname].call(this, attrs);
    }
  }).bind(this));

  this._parser.on('endElement', (function onParserEndElement(name) {
    if ((primaryElements.indexOf(name) < 0)) return;
github redaktor / owl2jsonschema.js / lib / rdf2json.js View on Github external
* Parses rdf to json using node-expat.
	 * @param {String|Buffer} xml The xml to be parsed to json.
	 * @param {Object} _options An object with options provided by the user.
	 * The available options are:
	 *  - object: If true, the parser returns a Javascript object instead of
	 *            a JSON string.
	 *  - reversible: If true, the parser generates a reversible JSON, mainly
	 *                characterized by the presence of the property $.
	 *  - sanitize_values: If true, the parser escapes any element value in the xml
	 * that has any of the following characters: <, >, (, ), #, #, &, ", '.
	 *
	 * @return {String|Object} A String or an Object with the JSON representation
	 * of the XML.
	 */

    var parser = new expat.Parser('UTF-8');
	
    parser.on('startElement', start);
    parser.on('text', text);
    parser.on('endElement', end);

    obj = cur = {};
    ancestors = [];
    curName = null;

    //configuration options
	options = _options;

    if (!parser.parse(xml)) throw new Error('There are errors in your xml file: ' + parser.getError());
	
	// TODO - delete this lines, just for DEBUG ! -->
	var fs = require('fs');
github msiebuhr / charcod.es / w3c-xml2json.js View on Github external
var args = argparse.argv;

// {{{ fixedFromCharCode(codePoint)
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/fromCharCode
function fixedFromCharCode (codePt) {
    if (codePt > 0xFFFF) {
        codePt -= 0x10000;
        return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
    } else {
        return String.fromCharCode(codePt);
    }
}
// }}}

// Parse XML
var parser = new expat.Parser("UTF-8"),
    output = args.output ? fs.createWriteStream(args.output) : process.stdout,
    input = args.input ? fs.createReadStream(args.input) : process.stdin,
    jsonStream = JSONStream.stringifyObject("{", ",\n", "}\n");

jsonStream.pipe(output);

// Parse!
var currentChar = {},
    currentText = "";
parser.on('startElement', function (name, attrs) {
    if (name === 'character' && attrs.dec && attrs.dec.match(/^\d+$/)) {
        currentChar = {
            code: parseInt(attrs.dec, 10), // Codepoint
            //name: attrs.na.toLowerCase(), // Name
            //block: attrs.blk.toLowerCase(), // Block
        }
github fb55 / htmlparser2 / tests / bench.js View on Github external
function ExpatParser() {
        var parser = new expat.Parser();
        this.parse = function(s) {
            parser.parse(s, false);
        };
    }
github osmlab / osm-meta-util / index.js View on Github external
function next()  {
        //Add padding
        var stateStr = that.state.toString().split('').reverse();
        var diff = 9 - stateStr.length;
        for (var i=0; i < diff; i++) { stateStr.push('0'); }
        stateStr = stateStr.join('');

        //Create URL
        var url = '';
        for (i=0; i<(stateStr.length/3); i++) {
            url += stateStr[i*3] + stateStr[i*3 + 1] + stateStr[i*3 + 2] + '/';
        }

        //XML Parser
        var xmlParser = new expat.Parser('UTF-8');
        xmlParser.on('startElement', parserStart);
        xmlParser.on('endElement', parserEnd);

        //Get YAML state file
        request.get('http://planet.osm.org/replication/changesets/state.yaml',
            function(err, response, body) {
                var nodata = true;
                //If YAML state is bigger, we can get a new file
                if (Number(body.substr(body.length - 8)) >= that.state) {
                    var ss = request.get(that.baseURL + url.split('').reverse().join('') + '.osm.gz')
                        .pipe(zlib.createUnzip())
                        .on('data', function(data) {
                          nodata = (data.length === 0) && nodata;
                        })
                        .on('end', function() {
                          if (nodata) {

node-expat

NodeJS binding for fast XML parsing.

MIT
Latest version published 1 month ago

Package Health Score

84 / 100
Full package analysis