Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different results selecting HTML elements with XPath in Firefox and Internet Explorer

I'm trying to select a specific HTML element in a document, for firefox i just use:

xpathobj = document.evaluate(xpath, document, null,
               XPathResult.FIRST_ORDERED_NODE_TYPE, null);

which works fine. However when I try the IE equivilent:

xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(document);
xmlDoc.setProperty("SelectionLanguage", "XPath");
xpathobj = xmlDoc.selectNodes(xpath);

I get no object returned. So my question is there an easy way to use XPath to get to the element I want in IE? The XPath I'm using looks like

/HTML/BODY/DIV[9]/DIV[2]
like image 593
user11198 Avatar asked Oct 07 '08 11:10

user11198


1 Answers

Take a look at http://dev.abiss.gr/sarissa/ project. They have migrated most of XML-related APIs to IE. Otherwise it is indeed also easy to implement. The problems you would need to solve would be: serialization of HTML into valid XML, syncing result of XMLDOM XPath query with original HTMLDOM. To my knowledge they've done it in their library, however, its performance could have been better.

like image 96
Sergey Ilinsky Avatar answered Oct 22 '22 05:10

Sergey Ilinsky