How to use the sax.parser 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 Cap32 / wxml-loader / src / index.js View on Github external
const isSourceAbsolute = isAbsolute(source);
		if (!isSourceAbsolute && !hasProcotol(source)) {
			source = ensureStartsWithDot(source);
		}
		if (enforceRelativePath && isSourceAbsolute) {
			source = ensureRelativePath(source);
		}

		/* istanbul ignore else */
		if (typeof transformUrl === 'function') {
			source = transformUrl(source, resource);
		}
		content = replaceAt(content, startIndex, endIndex, source);
	};

	const parser = sax.parser(false, { lowercase: true });

	parser.onattribute = ({ name, value }) => {
		if (
			!value ||
			!isSrc(name) ||
			isDynamicSrc(value) ||
			!isUrlRequest(value, root)
		) {
			return;
		}

		const endIndex = parser.position - 1 - ROOT_TAG_LENGTH;
		const startIndex = endIndex - value.length;
		const request = urlToRequest(value, root);

		requests.unshift({ request, startIndex, endIndex });
github lula / ngx-soap / src / libts / wsdl.ts View on Github external
xmlToObject(xml: any, callback?: any) {
    var self = this;
    // var p = typeof callback === 'function' ? {} : saxParser(true, {});
    var p = sax.parser(true, {});
    var objectName: any = null;
    var root: any = {};
    var schema: any = {
      Envelope: {
        Header: {
          Security: {
            UsernameToken: {
              Username: 'string',
              Password: 'string'
            }
          }
        },
        Body: {
          Fault: {
            faultcode: 'string',
            faultstring: 'string',
github GPII / universal / node_modules / xml-mapping / lib / xml-mapping.js View on Github external
exports.load = function(str, options) {
	options = options || {};
	if (typeof str != "string") {
    if (options.throwErrors) {
      throw new Error("Input was "+(typeof str)+", expected a string");
    }
    return str;
  }

	var parser = require("sax").parser(true, {trim:true, xmlns:false});
	var result = {}, 
		stack = [], 
		cdata = '';

	function cvalue(n, v) {
		n = n.replace(':', '$');
		var o = stack[stack.length-1];
		if (o == undefined) {
			o = {};
			o[n] = v;
			return o[n];
		}
		else if (o[n] == undefined) {
			o[n] = v;
			return o[n];
		}
github vivainio / robotframework-vscode / src / extension.ts View on Github external
parse(cont: string) {
		const parser = sax.parser(false);
		let current_kw = '';
		let current_args = [];
		let current_text = '';
		parser.onopentag = (node) => {
			if (node.name == 'KW') {
				current_kw = node.attributes.NAME;
				current_args = [];
			}
			if (node.name == 'ARG') {
				current_text = '';
			}
		}
		parser.ontext = (text) => current_text = text;
		parser.onclosetag = (tag => {
			if (tag == 'ARG') {
				current_args.push(current_text);
github yodaos-project / ShadowNode / src / js / dbus.js View on Github external
function xml2js(buf) {
  var json = {};
  var curr = json;
  var history = [];
  var parser = sax.parser(true);
  parser.onopentag = function(node) {
    if (!Array.isArray(curr)) {
      curr[node.name] = {
        attributes: node.attributes,
        children: [],
      };
      history.push(curr);
      curr = json[node.name].children;
    } else {
      curr.push({
        name: node.name,
        attributes: node.attributes,
        children: [],
      });
      history.push(curr);
      curr = curr[curr.length - 1].children;
github elexis-eu / lexonomy / website / adminscripts / import.js View on Github external
function importDictionary(entryTag, entryTotal) {
  var saxParser = sax.parser(true, {trim: false, strictEntities: false, xmlns: true, position: true, normalize: false, lowercase: false})
  var tagNameLength = entryTag.length + 2
  var currBeg;
  db.run("BEGIN TRANSACTION")
  saxParser.onerror = function (e) {
    saxParser.error = null
    saxParser.resume()
  }
  saxParser.onopentagstart = function (node) {
    if (node.name == entryTag)
      currBeg = saxParser.position - tagNameLength;
  }
  saxParser.onclosetag = function (node) {
    if (node == entryTag) {
      entry = input.substring(currBeg, saxParser.position).replace(/\>[\r\n]+\s*\<").trim()
      importEntry(entry, entryTotal)
    }
github CGamesPlay / hterminal / client / HTMLParser.js View on Github external
export function parseHTML(data) {
  var parser = sax.parser(true);
  var stack = [];
  parser.onopentag = function(node) {
    stack.push(node);
    node.children = [];
  };
  parser.ontext = function(text) {
    stack[stack.length - 1].children.push(text);
  };
  parser.onclosetag = function() {
    let node = stack.pop();
    let type = ComponentLibrary[node.name] || ComponentLibrary['span'];
    let attributes = Object.keys(node.attributes).reduce((memo, attr) => {
      let propType = type.propTypes && type.propTypes[attr];
      if (propType && propType(node.attributes, attr) === null) {
        memo[attr] = node.attributes[attr];
      }
github jbeard4 / SCION / lib / compiler / static-analysis / scxml-analyzer.js View on Github external
var esprima = require('esprima');
var parser = require("sax").parser(true, { trim: true, xmlns: true, position: true });


var systemVariables = ["_event", "_sessionid", "_name", "_ioprocessors", "_x"];
var eventProcessorTypes = {
    'http://www.w3.org/TR/scxml/#SCXMLEventProcessor' : 'SCXMLEventProcessor',
    'http://www.w3.org/TR/scxml/#BasicHTTPEventProcessor': 'BasicHTTPEventProcessor',
    'http://www.w3.org/TR/scxml/#DOMEventProcessor': 'DOMEventProcessor'
};

var currentScxml, originalScxml, result, lastOpenScriptTagPosition, currentJsScriptTag;

var scxmlAnalyzer = {
	analyze: function (scxml) {
		currentScxml = originalScxml = scxml;
		result = {
			errors: [],
github michaelnisi / pickup / lib / pickup.js View on Github external
function pickup () {
  var currentTag = null
  ,   item = null
  ,   withinItem = false
  ,   ignored = true
  ,   parser = sax.parser(true, { trim: true })
  ,   stream = stringify(parser)
 
  parser.onopentag = function (node) {
    var tag = replace(node.name)
    
    ignored = !relevant(tag)

    if (ignored) {
      if (!withinItem) item = null
      return
    }

    currentTag = tag
    
    if (tag === 'item') withinItem = true
github andrewrk / node-tmx-parser / index.js View on Github external
function parse(content, pathToFile, cb) {
  var pathToDir = path.dirname(pathToFile);
  var parser = sax.parser();
  var map;
  var topLevelObject = null;
  var state = STATE_START;
  var states = new Array(STATE_COUNT);
  var waitForCloseNextState = 0;
  var waitForCloseOpenCount = 0;
  var propertiesObject = null;
  var propertiesNextState = 0;
  var animationsObject = null;
  var animationsNextState = 0;
  var objectGroupsObject = null;
  var objectGroupsNextState = 0;
  var tileIndex = 0;
  var tileSet = null;
  var tileSetNextState = 0;
  var tile;

sax

An evented streaming XML parser in JavaScript

ISC
Latest version published 7 months ago

Package Health Score

80 / 100
Full package analysis