Gathering detailed insights and metrics for slimdom-sax-parser
Gathering detailed insights and metrics for slimdom-sax-parser
Gathering detailed insights and metrics for slimdom-sax-parser
Gathering detailed insights and metrics for slimdom-sax-parser
Parse an XML string to a light-weight spec-compliant document object model, for browser and Node
npm install slimdom-sax-parser
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
168,308
Last Day
839
Last Week
4,236
Last Month
6,944
Last Year
41,887
MIT License
9 Stars
67 Commits
5 Forks
5 Watchers
8 Branches
6 Contributors
Updated on Jan 22, 2025
Minified
Minified + Gzipped
Latest Version
1.5.3
Package Id
slimdom-sax-parser@1.5.3
Unpacked Size
125.65 kB
Size
23.45 kB
File Count
20
NPM Version
8.5.5
Node Version
16.15.0
Cumulative downloads
Total Downloads
Last Day
254%
839
Compared to previous day
Last Week
151.8%
4,236
Compared to previous week
Last Month
173.9%
6,944
Compared to previous month
Last Year
99%
41,887
Compared to previous year
4
Parses XML to a slimdom document using saxes. slimdom is a fast, tiny, standards-compliant XML DOM implementation for browser and node.
Has two named exports:
async
(function) Asynchronously return a slimdom Document for the given XML string or Readable stream.sync
(function) Synchronously return a slimdom Document for the given XML string:slimdom
(slimdom) A reference to the lib this parser is built around, as a convenience.The shape of the async
function is as follows;
1function async( 2 xml: string | stream.Readable, 3 options?: saxes.SaxesOptions & { 4 additionalEntities?: { 5 [entityName: string]: string; 6 }; 7 } 8): Promise<slimdom.Document>;
The shape of the sync
function is as follows;
1function sync( 2 xml: string, 3 options?: saxes.SaxesOptions & { 4 additionalEntities?: { 5 [entityName: string]: string; 6 }; 7 } 8): slimdom.Document;
See also saxes.SaxesOptions and the standard DOM API.
1import { async } from 'slimdom-sax-parser'; 2 3const dom = await async('<xml foo="bar" />');
1import { sync } from 'slimdom-sax-parser'; 2 3const dom = sync('<xml foo="bar" />');
Modify the XML DOM:
1import { sync } from 'slimdom-sax-parser'; 2 3const document = sync(`<foo />`); 4 5document.documentElement.setAttribute('bar', 'baz'); 6// document.documentElement.hasAttribute('bar') === true
Use with an XPath engine (fontoxpath):
1import { sync } from 'slimdom-sax-parser'; 2import { evaluateXPath } from 'fontoxpath'; 3 4const document = sync(`<foo><bar /><baz /></foo>`); 5const childNodeNames = evaluateXPath('/foo/*/name()', document); 6// childNodeNames equals ['bar', 'baz']
Use source code position tracking:
1import { slimdom, sync } from 'slimdom-sax-parser'; 2 3const xml = '<example><child-element /></example>'; 4 5const document = sync(xml, { position: true }); 6// document instanceof slimdom.Document === true 7 8const childElement = document.documentElement.firstChild; 9// childElement instanceof slimdom.Element === true 10 11const position = childElement.position; 12// xml.substring(position.start, position.end) === '<child-element />'
Transform a XML file:
1import fs from 'fs'; 2import { async, slimdom } from 'slimdom-sax-parser'; 3import { evaluateXPathToNodes } from 'fontoxpath'; 4 5async function transform(filePath) { 6 const xmlStream = fs.createReadStream(filePath); 7 const document = await async(xmlStream); 8 9 const barNodes = evaluateXPathToNodes('//bar/*', document); 10 for (const barNode of barNodes) { 11 barNode.setAttribute('bar', 'baz'); 12 } 13 14 await fs.promises.writeFile(filePath, slimdom.serializeToWellFormedString(document)); 15} 16 17transform('./file.xml');
Copyright (c) 2019 Wybe Minnebo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/22 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
16 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More