How to use the sax.SAXParser 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 dtjohnson / xlsx-populate / src / XmlParser.ts View on Github external
return new Promise((resolve, reject) => {
            // Create the SAX parser.
            const parser = new SAXParser(true);

            // Parsed is the full parsed object. Current is the current node being parsed. Stack is the current stack of
            // nodes leading to the current one.
            let parsed: INode, current: INode;
            const stack: INode[] = [];

            // On error: Reject the promise.
            parser.onerror = reject;

            // On text nodes: If it is all whitespace, do nothing. Otherwise, try to convert to a number and add as a child.
            parser.ontext = text => {
                if (allWhitespaceRegex.test(text)) {
                    if (current && current.attributes && current.attributes['xml:space'] === 'preserve') {
                        if (!current.children) current.children = [];
                        current.children.push(text);
                    }

sax

An evented streaming XML parser in JavaScript

ISC
Latest version published 7 months ago

Package Health Score

77 / 100
Full package analysis