0

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?

Some existing JavaScript XPath work:
http://js-xpath.sourceforge.net/xpath-example.html
http://goog-ajaxslt.sourceforge.net

12
  • 1
    Seems like you answered your own question doesn't it? Commented Sep 12, 2010 at 14:39
  • What makes you think XPath could be converted to regex? Commented Sep 12, 2010 at 14:41
  • About using regex to parsse HTML: stackoverflow.com/questions/1732348/… Commented Sep 12, 2010 at 16:02
  • 2
    PLEASE STOP LINKING THAT ANSWER IT MAKES ME ANGRIER THAN THE GUY WHO WROTE IT /<html>.*<\/html>/g KAJSHDKAJSHDKASHD Commented Sep 12, 2010 at 16:14
  • 1
    @Richard: What browsers are you targeting? I ask because up today selectNodes works for IE and evaluate works for Firefox, Chrome, Opera and Safari... Commented Sep 14, 2010 at 22:48

2 Answers 2

1

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

This looks interesting too:

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.