Gathering detailed insights and metrics for xpath
Gathering detailed insights and metrics for xpath
Gathering detailed insights and metrics for xpath
Gathering detailed insights and metrics for xpath
npm install xpath
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
225 Stars
205 Commits
71 Forks
6 Watching
9 Branches
2 Contributors
Updated on 10 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-15%
531,238
Compared to previous day
Last week
0.3%
2,922,933
Compared to previous week
Last month
13.4%
12,551,668
Compared to previous month
Last year
31.5%
113,640,033
Compared to previous year
4
DOM 3 XPath 1.0 implemention and helper for JavaScript, with node.js support.
Originally written by Cameron McCormack (blog).
Additional contributions from
Yaron Naveh (blog)
goto100
Thomas Weinert
Jimmy Rishe
and others
Install with npm:
npm install xpath
xpath is xml engine agnostic but we recommend xmldom:
npm install @xmldom/xmldom
Can be found here. See below for example usage.
1var xpath = require('xpath'); 2var dom = require('@xmldom/xmldom').DOMParser; 3 4var xml = "<book><title>Harry Potter</title></book>"; 5var doc = new dom().parseFromString(xml, 'text/xml'); 6var nodes = xpath.select("//title", doc); 7 8console.log(nodes[0].localName + ": " + nodes[0].firstChild.data); 9console.log("Node: " + nodes[0].toString());
➡
title: Harry Potter
Node: <title>Harry Potter</title>
Using the same interface you have on modern browsers (MDN)
1var node = null; 2var xml = "<book author='J. K. Rowling'><title>Harry Potter</title></book>"; 3var doc = new dom().parseFromString(xml, 'text/xml'); 4var result = xpath.evaluate( 5 "/book/title", // xpathExpression 6 doc, // contextNode 7 null, // namespaceResolver 8 xpath.XPathResult.ANY_TYPE, // resultType 9 null // result 10); 11 12node = result.iterateNext(); 13while (node) { 14 console.log(node.localName + ": " + node.firstChild.data); 15 console.log("Node: " + node.toString()); 16 17 node = result.iterateNext(); 18}
➡
title: Harry Potter
Node: <title>Harry Potter</title>
1var xml = "<book><title>Harry Potter</title></book>"; 2var doc = new dom().parseFromString(xml, 'text/xml'); 3var title = xpath.select("string(//title)", doc); 4 5console.log(title);
➡
Harry Potter
1var xml = "<book><title xmlns='myns'>Harry Potter</title></book>"; 2var doc = new dom().parseFromString(xml, 'text/xml'); 3var node = xpath.select("//*[local-name(.)='title' and namespace-uri(.)='myns']", doc)[0]; 4 5console.log(node.namespaceURI);
➡
myns
1var xml = "<book xmlns:bookml='http://example.com/book'><bookml:title>Harry Potter</bookml:title></book>" 2var select = xpath.useNamespaces({"bookml": "http://example.com/book"}); 3 4console.log(select('//bookml:title/text()', doc)[0].nodeValue);
➡
Harry Potter
1var xml = "<book xmlns='http://example.com/book'><title>Harry Potter</title></book>" 2var select = xpath.useNamespaces({"bookml": "http://example.com/book"}); 3 4console.log(select('//bookml:title/text()', doc)[0].nodeValue);
➡
Harry Potter
1var xml = "<book author='J. K. Rowling'><title>Harry Potter</title></book>"; 2var doc = new dom().parseFromString(xml, 'text/xml'); 3var author = xpath.select1("/book/@author", doc).value; 4 5console.log(author);
➡
J. K. Rowling
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
5 existing vulnerabilities detected
Details
Reason
Found 4/11 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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
Score
Last Scanned on 2024-11-25
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