Version 16 (modified by amachang, 6 years ago)

--

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

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
  • 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/node()[1]', document, null, 2, null);
    alert(result.stringValue); // JavaScript-XPath
    

Functional Test

Speed Test

  • Coming soon.

Binding

  • Coming soon.