[Home] [By Thread] [By Date] [Recent Entries]

  • To: xml-dev@l...
  • Subject: DOM traversal: NodeIterator + NodeFilter vs. TreeWalker
  • From: Razvan MIHAIU <mihaiu@m...>
  • Date: Sun, 20 Mar 2005 11:49:14 +0200
  • User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)


Hi,



It seems to me that TreeWalker can very easily be simulated using 
NodeIterator with a Nodefilter. In Java my filter could look like this:

class CustomFilter implements NodeFilter
{
public short acceptNode(Node node)
{
…
}
}

Since the member function acceptNode() takes a node as its input that 
means that in this function I have access to all member functions of the 
Node object:

|*getFirstChild <cid:part1.09080503.07000705@m...>*()
*getLastChild <cid:part2.00040703.07070505@m...>*()
*getNextSibling <cid:part3.07060006.03010105@m...>*||()
*getParentNode <cid:part4.05070703.04020808@m...>*||()|

| a.s.o.|

| Using those functions I can fully access the DOM tree even if the 
object implementing NodeIterator is not aware of the tree-like structure 
of DOM. Isn’t this the “r|eason d'être”| for the TreeWalker interface ? 
(the fact that NodeIterator uses a ‘flat’ model for its DOM 
representation)||
Are there situation where a TreeWalker is more appropriate than a 
NodeIterator + NodeFilter ? Please provide an example.|

|


Regards,
Razvan|

|www.mihaiu.name <http://www.mihaiu.name/>
|

|
|


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member