How to use the sax.createStream function in sax

To help you get started, we’ve selected a few sax 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 danja / seki / srx2map.js View on Github external
// sax settings
var strict = true; // set to false for html-mode
var options = {};

// flag for position in XML  ...here if true ... 
var inBinding = false;

// values to extract from the XML
var element = "";
var bindingName = "";
var bindingValue = "";
var bindingType = "";

// create a stream parser
var saxStream = sax.createStream(strict, options);

// make it available to other scripts
exports.createStream = function() {
    return saxStream;
};

// minimal parse error handling
saxStream.on("error", function(e) {
    console.error("SAX parse error", e);
});

// handle an opening tag
// loosely corresponds to SAX startElement(...)
saxStream.on("opentag", function(node) {

    element = node.name;
github itteco / iframely / lib / iframely-meta.js View on Github external
function xmlStream2oembed(stream, callback) {
        var oembed;
        var prop;
        var value;
        var firstTag;

        var charset = getCharset(stream.headers && stream.headers['content-type']);

        var saxStream = sax.createStream();
        saxStream.on('error', function(err) {
            callback(err);
        });
        saxStream.on('opentag', function(tag) {
            if (!firstTag) {
                // Should be HEAD but HASH tag found on qik.
                firstTag = tag.name;
                oembed = {};
            } else if (oembed) {
                prop = tag.name.toLowerCase();
                value = "";
            }
        });
        saxStream.on('text', function(text) {
            if (prop) value += text;
        });
github vpulim / node-soap / src / wsdl / index.ts View on Github external
} else {
            value = top.object + text;
          }
        }
      }

      if (top.object[this.options.attributesKey]) {
        top.object[this.options.valueKey] = value;
      } else {
        top.object = value;
      }
    };

    if (typeof callback === 'function') {
      // we be streaming
      const saxStream = sax.createStream(true, null);
      saxStream.on('opentag', p.onopentag);
      saxStream.on('closetag', p.onclosetag);
      saxStream.on('cdata', p.oncdata);
      saxStream.on('text', p.ontext);
      xml.pipe(saxStream)
      .on('error', (err) => {
        callback(err);
      })
      .on('end', () => {
        let r;
        try {
          r = finish();
        } catch (e) {
          return callback(e);
        }
        callback(null, r);
github exceljs / exceljs / lib / stream / xlsx / worksheet-reader.js View on Github external
const {sharedStrings} = this.workbook;
    const {styles} = this.workbook;
    const {properties} = this.workbook;

    // xml position
    let inCols = false;
    let inRows = false;
    let inHyperlinks = false;

    // parse state
    let cols = null;
    let row = null;
    let c = null;
    let current = null;

    const parser = Sax.createStream(true, {});
    parser.on('opentag', node => {
      if (emitSheet) {
        switch (node.name) {
          case 'cols':
            inCols = true;
            cols = [];
            break;
          case 'sheetData':
            inRows = true;
            break;

          case 'col':
            if (inCols) {
              cols.push({
                min: parseInt(node.attributes.min, 10),
                max: parseInt(node.attributes.max, 10),
github racker / glimpse.js / grunt / tasks / compile-svg.js View on Github external
function processFile(filePath) {
        // Read in an SVG file.
        var readStream = fs.createReadStream(filePath),
            saxStream = sax.createStream(false,
              { normalize: true, lowercase: true }),
            indent = 2;

        saxStream.on('error', function() {
          grunt.log.error('Error parsing SVG file.');
        });

        saxStream.on('end', function() {
          fileReadCount += 1;
          if (fileCount === fileReadCount) {
            wrapEnd(writeStream);
            writeStream.destroySoon();
          }
        });

        // Write out open tags and attrs if not ignored.
github exceljs / exceljs / lib / stream / xlsx / hyperlink-reader.js View on Github external
emitHyperlinks = true;
        break;
      case 'cache':
        this.hyperlinks = hyperlinks = {};
        break;
      default:
        break;
    }

    if (!emitHyperlinks && !hyperlinks) {
      entry.autodrain();
      this.emit('finished');
      return;
    }

    const parser = Sax.createStream(true, {});
    parser.on('opentag', node => {
      if (node.name === 'Relationship') {
        const rId = node.attributes.Id;
        switch (node.attributes.Type) {
          case RelType.Hyperlink: {
            const relationship = {
              type: Enums.RelationshipType.Styles,
              rId,
              target: node.attributes.Target,
              targetMode: node.attributes.TargetMode,
            };
            if (emitHyperlinks) {
              this.emit('hyperlink', relationship);
            } else {
              hyperlinks[relationship.rId] = relationship;
            }
github PomanoB / lsse / import_lemms.js View on Github external
db.createCollection('lemms', function(err, collection){
		if(err) 
		{
			console.log(err);
			db.close();
			return;
		}

		var saxStream = sax.createStream(true);


		var numberLemms = 0;

		var currentTag = 0;
		var currentEntry = {}
		var TagsTypes = {
			"entry": 1,
			"lemma": 2,
			"form": 3
		};

		saxStream.on("error", function (e) {
			console.error("error!", e)
			
			this._parser.error = null
github TimelordUK / jspurefix / src / dictionary / parser / fix-repository / repository-xml-parser.ts View on Github external
private async onePass (fileName: string): Promise {
    const logger = this.logger
    const fullFileName = path.join(this.rootPath, fileName)
    const pass: fs.ReadStream = fs.createReadStream(fullFileName)
    logger.info(`reading ${fullFileName}`)
    const saxStream: SAXStream = require('sax').createStream(true, {})
    pass.pipe(saxStream)
    await this.singlePass(this, saxStream)
  }
}

sax

An evented streaming XML parser in JavaScript

ISC
Latest version published 6 months ago

Package Health Score

78 / 100
Full package analysis