Javascript-XPath

JavaScript-XPath是一个基于Javascript的高效的DOM 3 XPath (XPath 1.0)的解析器,支持IE6以上版本以及所有其它的现代浏览器

官方网站为:http://coderepos.org/share/wiki/JavaScript-XPath

官网示例:

 
<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>

No Responses

Leave a Comment

(Necessary)

(Necessary, will not be published)

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.