473,385 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

document.evaluate() act unusual.

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
1 1861
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
1
by: james.kingston | last post by:
In my first experimentation with js, I'm writing a greasemonkey script which adds links to a page which, when clicked, will replace their parent element with the contents of an element from another...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
5
by: Csaba Gabor | last post by:
In Firefox 1.5 (this question is Mozilla specific as I am using greasemonkey) I would like to be able to use document.evaluate to return the first TD entry that shows ^\s*MySearchText\s*$. As I...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
1
by: ppcguy | last post by:
i've got this in firefox and it works var xpath_result = document.evaluate("id('main')/tbody", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); var table =...
2
by: Björn Langhof | last post by:
Hello. I want to evaluate a XPath-Expression only on a subtree of the whole xml-document. 1. I select a node of the XML-document 2. Then a want to select specific nodes below the node chosen...
1
by: shellon | last post by:
Hi all: I met a problem when using document.evaluate() to get text content using XPath, my code is as follows: nodes = document.evaluate("/html/body/div/ul/li", document, null,XPathResult....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.