[x-posted to netscape.public.mozilla.dom, follow-up to
netscape.public.mozilla.dom]
/Antônio Gomes/:
So, let me ask first if it this the right mail list to
asking question related to TreeWalker ? If so, here we go (if no, point
me the one, please):
I guess "netscape.public.mozilla.dom" [1] is more suited. See my
reply below the quote.
** I'm able to build a custom DOM tree from the original DOM tree using
the following peace of code :
The walker doesn't build another DOM - just presents a filtered view
of an existing one.
/************** quoted filter method **************/
if (node.localName == "IMG") // for images
return nodeFilter.FILTER_ACCEPT;
else if (node.contentDocument )// for frames
return nodeFilter.FILTER_ACCEPT;
return nodeFilter.FILTER_SKIP;
/************** walking **************/
// walk the TreeWalker tree...
if(walker.firstChild()) {
do {
/* quoted */
addTree(walker, destNode);
} while(walker.nextSibling());
// don't forget to return the treewalker to it's previous state
// before exiting the function
while (walker.parentNode() != null);
}
But, should these steps create a new DOM tree from the original
(containing the "accepted" nodes only) ? Or will the filter be applyed
everytime that a walking-through is requested ? I mean, an "inline"
walking ...
ps: there is a lot of documentation available on the net, but all of
them are ambiguous at this point.
I don't know what the addTree() function above does and why it needs
the walker as argument but I don't think there's any ambiguity.
Again, from the spec:
As with NodeIterators, a TreeWalker may be active while the data
structure it navigates is being edited, and must behave gracefully
in the face of change. Additions and removals in the underlying data
structure do not invalidate a TreeWalker; in fact, a TreeWalker is
never invalidated.
As I've already pointed the TreeWalker state is dependent on its
'currentNode'. Every operation firstChild(), nextSibling(), etc. is
relative to it. The filter may be applied/invoked multiple times
during one call to the TreeWalker methods.
[1] http://www.mozilla.org/community/developer-forums.html#mozilla-dom
--
Stanimir
_______________________________________________
mozilla-layout mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-layout