JavaScript-XPath
JavaScript-XPath is the FASTEST DOM 3 XPath (XPath 1.0) implementation in JavaScript.
This code runs 10 times faster than Google Ajaxslt's xpath.js!!
Release/Download
- Latest Version
- Latest Compressed Version
- If you can use subversion, check out the trunk with:
svn co http://svn.coderepos.org/share/lang/javascript/javascript-xpath/trunk/ jsxpath
Bindings
How to use
- Import JavaScript-Xpath JavaScript File (this js file does nothing for browsers which support DOM 3 XPath natively).
- Enjoy with DOM 3 XPath!
Simple Example
<html> <head><title>Hello, DOM 3 XPath!</title> <!-- import JavaScript-XPath --> <script type="text/javascript" src="javascript-xpath.js"></script> <!-- use XPath --> <script type="text/javascript"> // <![CDATA[ function main() { // -- First case -- // Evaluate a XPath expression string var result = document.evaluate('//h1', document, null, 7, null); // Display the result var h1 = result.snapshotItem(0); alert(h1.innerHTML); // Hello, DOM 3 XPath! // -- Second case -- // Create a XPath expression object var expr = document.createExpression('//h1', null); // Evaluate a XPath expression object result = expr.evaluate(document, 7, null); // Display the result h1 = result.snapshotItem(0); alert(h1.innerHTML); // Hello, DOM 3 XPath! }; // ]]> </script> </head><body onload="main()"><h1>Hello, DOM 3 XPath!</h1></body> </html>
Supported Browser
- Internet Explorer 6
- Internet Explorer 7
- Internet Explorer 8
- Safari 2+
- Any Other DOM Core Supported Browser
Native DOM 3 XPath Supported Browser
- Firefox 1+
- Safari 3+
- Opera 9+
Demo
- Simple demo.
//Executable var result = document.evaluate('//h1/text()[1]', document, null, 2, null); alert(result.stringValue); // JavaScript-XPath
- Performance demo.
//Executable var start_ = new Date; var result = document.evaluate('//div', document, null, 6, null); alert(result.snapshotLength + ' elements in ' + (new Date - start_) + ' [ms]');
Functional Test
Speed Test
- Coming soon.