XPath Support

In Mozilla/Firefox, XPath is supported by evaluate(), document.evaluate(xPathTerm, contents, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null); In Internet Explorer, no related functionality implemented. But the user can use a third-party package to use part of evaluate(), by including the script of xpath.js in user script. In xpath.js, selectNodes() method is supported. For more information, please refer to the further reading part.

Note: XPath implemented in this way is slow for the page processing, so pay attention to it.

In many cases, one can use general method instead XPath, a better way for IE.

The following code get all the images which contains "/profile" in its src attribute: with XPath, var allImages; allImages = document.evaluate( '//img[contains(@src, "/profile")]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); or without it, var allImages = []; var tmpImages = document.getElementsByTagName('img'); for(var i = 0,j=0; i< tmpImages.length; i++){ if(tmpImages[i].src.indexOf('/profile') != -1){ allImages[j] = img; j++; } }

Further Readings for XPath:

http://js-xpath.sourceforge.net/

http://www.koders.com/javascript/fidBB62C35FD13B7C012312BF1959DE45CCBDC6C86B.aspx?s=xml

DOM3 XPath

Code Example:BaiduMP3ShowDownloadUrl.ieuser.js