xpath not working for firefox 3.6

21 views
Skip to first unread message

james

unread,
Jan 24, 2010, 10:34:28 PM1/24/10
to greasemonkey-users
xpath parser is not working in the greasemonkey scripts.

my scripts heavily use the function "doc.evaluate(xpath, node, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)".

it works with 3.5, but NOT with 3.6.

esquifit

unread,
Jan 25, 2010, 6:02:40 AM1/25/10
to greasemon...@googlegroups.com
For me it's still working fine. Could you please point to a specific script?

chin

unread,
Jan 27, 2010, 1:26:25 AM1/27/10
to greasemonkey-users
my xpath is not working in firefox3.6, too

my code sample :

var XPFirst = XPathResult.FIRST_ORDERED_NODE_TYPE;
var XPList = XPathResult.ORDERED_NODE_SNAPSHOT_TYPE;

function getSnapshotItem(resText, xpath, xpType){
if (xpType==null) xpType = XPFirst;
var aDoc = document.implementation.createDocument("", "", null);
var aElem = document.createElement('DIV');
aElem.innerHTML = resText;
aDoc.appendChild(aElem);
var ret = aDoc.evaluate(xpath, aElem, null, xpType, null);
return xpType==XPFirst ? ret.singleNodeValue : ret;
}

function onSpielerComplete(XMLHttpRequest, textStatus){
if (textStatus=="success"){
var table = getSnapshotItem(XMLHttpRequest.responseText, "//table
[@id='villages']");
}
}

in firefox 3.5, i can get table as a table dom element
but in firefox 3.6, table == null !

Could anyone please help ?

Brian L. Matthews

unread,
Jan 29, 2010, 7:21:00 PM1/29/10
to greasemon...@googlegroups.com

I don't see anything obviously wrong, so I'd just install Firebug on
both 3.5 and 3.6, then either step through the code or add appropriate
console.log calls and figure out where things first differ. For example,
are resText and aDoc the same in both cases?

Brian

chin

unread,
Jan 31, 2010, 10:59:15 PM1/31/10
to greasemonkey-users
i make a sample html

<script>
window.onload = function(){


var aDoc = document.implementation.createDocument("", "", null);
var aElem = document.createElement('DIV');

aElem.innerHTML = "<table id='ptable'><tr><td>this is a table</td></
tr></table>";
aDoc.appendChild(aElem);
var ret = aDoc.evaluate("//table[@id='ptable']", aElem, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null);
alert("navigator.userAgent : " + navigator.userAgent + "\r\n\r\n" +
"ret.singleNodeValue : " + ret.singleNodeValue);
}
</script>

This html will alert ret.singleNodeValue content
in 3.5 : ret.singleNodeValue : [object HTML TableElement]
in 3.6 : ret.singleNodeValue : null

i maked a test link here :
http://chin99.myweb.hinet.net/code/test_xpath.html

Need Help Plz ! Thanks a lot !

Angus

unread,
Feb 5, 2010, 2:53:02 AM2/5/10
to greasemonkey-users

jokke

unread,
Feb 15, 2010, 4:16:33 AM2/15/10
to greasemonkey-users
This workaround did help at least me. I couldn't find any tr elements
from a document using "//tr" XPath, but now with Agnus' namespace fix,
"//ns:tr" correctly returns 56 tr elements from the document I'm
trying to parse.

What was the problem with this one?

On Feb 5, 9:53 am, Angus <angus...@gmail.com> wrote:
> http://angusdev.blogspot.com/2010/02/fixing-xpath-problem-in-firefox-...

X

unread,
Mar 27, 2010, 4:49:43 PM3/27/10
to greasemonkey-users

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)6.

Reply all
Reply to author
Forward
0 new messages