By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,932 Members | 1,468 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,932 IT Pros & Developers. It's quick & easy.

document.evaluate() act unusual.

P: n/a
Hi all:
when I use XPather(a firefox extension) to evaluate the expression:
"/html/body/table[3]/tbody/tr/td[2]/table/tbody/tr/td/div/ul[1]/li"

it tells me there are 7 matching Nodes.

but when I use the following code to do the same thing:
nodes =
document.evaluate("/html/body/table[3]/tbody/tr/td[2]/table/tbody/tr/td/div/ul[1]/li",
document, null,XPathResult. ORDERED_NODE_SNAPSHOT_TYPE , null);
len = nodes.snapshot(0).childNodes.length;
the len returns 2.

so the XPather and firefox javascript returns different results,
generally I think the result of XPather is right. I can't tell why
javascript returns 2 here

Appreciate your help!

the site I test the expression is :
http://www.amazon.com/exec/obidos/AS...667641-1219860

Nov 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
shellon wrote:
when I use XPather(a firefox extension) to evaluate the expression:
"/html/body/table[3]/tbody/tr/td[2]/table/tbody/tr/td/div/ul[1]/li"

it tells me there are 7 matching Nodes.

but when I use the following code to do the same thing:
nodes =
document.evaluate("/html/body/table[3]/tbody/tr/td[2]/table/tbody/tr/td/div/ul[1]/li",
document, null,XPathResult. ORDERED_NODE_SNAPSHOT_TYPE , null);
len = nodes.snapshot(0).childNodes.length;
the len returns 2.

so the XPather and firefox javascript returns different results,
generally I think the result of XPather is right. I can't tell why
javascript returns 2 here
The evaluate method returns an XPathResult object, to check the length
of a snapshot returned you need to use e.g.
var xPathResult =
document.evaluate("/html/body/table[3]/tbody/tr/td[2]/table/tbody/tr/td/div/ul[1]/li",
document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
and then you can evaluate xPathResult.snapshotLength which should then
give you the number of nodes (e.g. 7).
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.