Firefox 3.5
var doc = document.implementation.createDocument("", "", null); div.innerHTML = html; doc.appendChild(div); var res = doc.evaluate("//p[@class='content']/span", div, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; // res is null
var isFF36up = false; if (navigator.userAgent) { var ffver = navigator.userAgent.match(/Firefox\/3\.(\d+)/); isFF36up = ffver && parseInt(ffver[1], 10) >= 6; } var nsResolver = { lookupNamespaceURI:function (prefix) { if (isFF36up && prefix == "ns") { return "http://www.w3.org/1999/xhtml"; } else { return ""; } } }; var doc = document.implementation.createDocument("", "", null); div.innerHTML = html; doc.appendChild(div); var res = doc.evaluate("//ns:p[@class='content']/ns:span", div, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
2 comments:
Aye! It actually works. Thanks a lot. Could you also explain what is the problem, or did you find the solution elsewhere?
var pulled = document.createElement('div');
pulled.innerHTML = responseDetails.responseText;
var pulleddoc = document.implementation.createDocument("", "", null);
pulleddoc.appendChild(pulled);
ex = "//ns:p[@class="error"]';
err = pulleddoc.evaluate(ex,pulled,nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
GM_log(pulled.innerHTML);
alert(err.innerHTML);
not working :( what i'm doing wrong ?
(ofc both functions are defined)
Post a Comment