Question

I known from one of stackoverflows reply that if we want to write Cross Browser XPath queries then there is a library exist called Wicked XPath Query from Google. Here is the link Wicked Good XPath

Does anybody has implemented such? If yes then please directs me on this regarding how to write Xpath query cross browser base. My targeted browsers are IE (7,8,9,10) and Google Chrome. Any working example which I can check in both IEs and Google Chrome will be appreciated.

I am expecting that solution should also be working in IE 10 too. The reason behind writing cross browser xpath is that I don't have to worry about any minor changes in executing xpath queries in different browsers.

Appreciating further assistance.

Edit:

Bit more explanation to solution from Sergey Ilinsky's answer which I accepted:

Here I am writing one example so that anyone who is working purely in XML data then they can get idea.

Let say if you have your XML structure like below one

<elementNode id="13" std="1">
    ....
</elementNode>

Then we can write xpath query like below

<script type="text/javascript">
    (function() {
        res = $.xpath($("#selectorID"),"//elementNode[@id='10']");
        console.log(res[0].getAttribute("id")); //will print 10 in console
        console.log(res[0].getAttribute("std")); //will print 1 in console
    })();
</script>
Was it helpful?

Solution

You may want to try jQuery XPath plugin with support for XPath 2.0 syntax cross-browser.

OTHER TIPS

Wicked Good XPath only supports HTML documents. All browsers support XPath for XML docs natively, though IE through a slightly different API. (selectNode, selectNodes instead of document.evaluate).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top