using xpaths in javascript
I have a large set of XPaths for selecting content in webpages and I want users to be able to use them in the browser (including IE).
What do you recommend? Try and interpret the XPaths with JavaScript?
Or perhaps convert to regex? 开发者_StackOverflow社区Some existing JavaScript XPath work:
http://js-xpath.sourceforge.net/xpath-example.html http://goog-ajaxslt.sourceforge.netI would look for an XSLT javascript library. Since most modern browsers have built-in XSLT support, and XSLT includes support for XPath, it is possible to use that engine to power your XPath selectors.
Personally, I've used Sarissa and the Glyphix jQuery.xslTransform libraries successfully:
- http://jquery.glyphix.com/
- http://dev.abiss.gr/sarissa/
This looks interesting too:
- http://johannburkard.de/software/xsltjs/
Nowadays browsers support the XPath 1.0 based DOM 3 XPath out of the box. The main API is the document.evaluate
function which is available in all mayor desktop browsers except IE.
And there are polyfills, if you want to use it in older browser versions or IE.
精彩评论