[DOMNodeIterator nextNode] continuing outside of root object?
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é, 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
On Apr 19, 2006, at 8:31 AM, Matt Gough wrote:
Can someone please confirm that [DOMNodeIterator nextNode] shouldn't be returning items outside of the root node that is passed into createNodeIterator.
The node iterator and tree walker implementations have problems. Luckily, this is rarely an issue since the classes aren't really all that helpful. I recommend iterating yourself using plain old DOM tree-walking calls like nextSibling, firstChild, etc. It's straightforward to do that. Bug reports about specific problems with node iterator would be welcome, since these may be important for website compatibility. Even more welcome would be patches to fix the node iterator and tree walker. -- Darin
participants (2)
-
Darin Adler
-
Matt Gough