473,395 Members | 2,689 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,395 software developers and data experts.

DOM Traversal: NodeIterator or TreeWalker?

I posted this question in a moribund group but now post it here:

I have an HTML document with a TABLE element and I want to count the number
of rows, presumably counting TR elements taking into account 'rowspan'
attributes; and the number of columns, presumably counting TH and TD
elements taking into 'colspan' attributes.

I have my own old code (probably bug-ridden) and would rather use the
Traversal DOM.

What is the best to use, a NodeInterator or TreeWalker? The use of the
NodeFilter is a bit confusing. If you have any advice I should consider
when I write this code, thanks.

I want this to work with MSIE too, and I usually write those DOM functions
as best as possible when MSIE has not implemented it. Has MS implemented
it?

Jul 11 '06 #1
3 5033


Patient Guy wrote:

I have an HTML document with a TABLE element and I want to count the number
of rows, presumably counting TR elements taking into account 'rowspan'
attributes; and the number of columns, presumably counting TH and TD
elements taking into 'colspan' attributes.
The HTML DOM for table elements has a rows collection and each row in
the rows collection has a cells collection.

What is the best to use, a NodeInterator or TreeWalker?
Has MS implemented
it?
No, MSIE does not support anything of DOM Level 2 Traversal.
Mozilla/Firefox has a TreeWalker implementation but no NodeIterator
implementation, Opera 8 and later has both NodeIterator and TreeWalker.
Not sure about Konqueror or Safari, maybe someone else can fill in.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 11 '06 #2
Martin Honnen wrote:
The HTML DOM for table elements has a rows collection and each row in
the rows collection has a cells collection.
However, given rowspan's and colspan's, finding the number of columns from
the .cells.length of the first row, for example, may be incorrect.
One would need to iterate over each cell and increase the count by 1 or the
colspan value.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 11 '06 #3
"Matt Kruse" <ne********@mattkruse.comwrote in comp.lang.javascript:
Martin Honnen wrote:
>The HTML DOM for table elements has a rows collection and each row in
the rows collection has a cells collection.

However, given rowspan's and colspan's, finding the number of columns
from the .cells.length of the first row, for example, may be
incorrect. One would need to iterate over each cell and increase the
count by 1 or the colspan value.
Very helpful information from you and Martin. Thanks for the coding tips.

And I guess I will have to make code for MSIE. A search of the archives
found script for implementing TreeWalker and I will check to see how well
it works.

Jul 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ravi mannan | last post by:
Hello all, I'm trying to read an xml file and create a nested JPopupMenu from that. The first thing I want to do is to read in the xml file and put it in a Document using DOM and then do a...
1
by: Jimmy Zhang | last post by:
I am trying to use node iterator of Xerces to traverse a DOM tree of a fairly small XML file. But I keep getting message saying running out of memory. Can someone take a look at my code to see...
0
by: Xamalaek | last post by:
Hello, I need some help with the DOM TreeWalker API. I modified the Xerces DOMPrint sample because I wanted to play around with the DOMTreeWalker API to iterate through the sample.xml file. ...
1
by: guy001 | last post by:
Hi, I'm trying to traverse the DOM in a bit of a non-traditional manner and am struggling to get my head around it. Just say i have some elements like so: A |-B |-C | |-D |
1
by: Patient Guy | last post by:
I am trying to write functions that manipulate objects representing dynamic tables in HTML documents in a more friendly way (to me). I do this by creating a table object (tableObject) through a...
2
by: xandra | last post by:
i have 2 question in breadth-first traversal.your help will be appreciated. 1. what is the purpose of the queue in breath-first traversal? 2 suppose you had a function call displayAtDepthN which...
6
by: GrispernMix | last post by:
//ques and and level order traversal file name: lab6_build_leaf_up.cpp Instructions:
7
by: Ward Germonpré | last post by:
Hi, On a html page I have a Table called "resultaattbl", generated using dom- methods and an array of jsobjects. The rows below the columnheader have a class called "normaal". This is the...
6
by: APEJMAN | last post by:
would you please help me? I wrote 3 separate line of code for printing my binary tree, and now I am trying to print the level-order traversal of the tree, where the nodes at each level of the tree...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.