[webkit-dev] [DOMNodeIterator nextNode] continuing outside of root object?

Matt Gough devlists at softchaos.com
Wed Apr 19 08:31:06 PDT 2006


Can someone please confirm that [DOMNodeIterator nextNode] shouldn't  
be returning items outside of the root node that is passed into  
createNodeIterator.

E.g. Consider the following snippet from Apple's Mac OS X web page  
(http://www.apple.com/macosx/):

(In its original form:)

<a href="/macosx/features/dashboard/"><img src="http:// 
images.apple.com/macosx/features/dashboard/images/ 
indexdashboard20050412.jpg" alt="Dashboard Widgets" width="440"  
height="275" border="0" class="across"></a>
			<p class="sosumi"><strong><a href="/macosx/features/ 
dashboard/">Dashboard</a>.</strong> Zooming to the top of your  
Desktop with the click of a function key, Dashboard, like  
Expos&#233;, disappears just as easily. Use Dashboard to access nifty  
new mini-applications called widgets.</p>


When I do the following:

DOMNode* rootNode <== This is set to the first <a> element above

DOMNodeIterator* iterator = [ownerDoc  
createNodeIterator:rootNode :DOM_SHOW_ALL :nil :NO];
DOMNode* node;
while ((node = [iterator nextNode]) != nil)
	;

I get all of the nodes from rootNode until the end of the document  
and not just the <a> and the <img> as expected.

This isn't always the case (i.e often it works as expected) but in  
this case it gets it wrong.

In this failing case, I have confirmed that the DOM itself has the  
right hierarchy.

This is with both the 418 WebKit and a recent TOT.

If someone could please confirm that this behaviour is not intended  
so i can file a proper bug report.

FYI - My simple workaround was:

DOMNode* rootNode <== This is set to the first <a> element above

DOMNode* badIteratorCatcher = [rootNode nextSibling] ? [rootNode  
nextSibling] : [rootNode parentNode];

DOMNodeIterator* iterator = [ownerDoc  
createNodeIterator:rootNode :DOM_SHOW_ALL :nil :NO];
DOMNode* node;
while (((node = [iterator nextNode]) != nil) && (node !=  
badIteratorCatcher))
	;


Matt Gough

Softchaos



More information about the webkit-dev mailing list