FileDocCategorySizeDatePackage
NameNodeListImpl.javaAPI DocJava SE 5 API8009Fri Aug 26 14:55:28 BST 2005com.sun.org.apache.html.internal.dom

NameNodeListImpl

public class NameNodeListImpl extends DeepNodeListImpl implements NodeList
This class implements the DOM's NodeList behavior for HTMLDocuemnt.getElementsByName().
version
$Id: NameNodeListImpl.java,v 1.6 2003/05/08 20:13:09 elena Exp $
since
PR-DOM-Level-1-19980818.
see
DeepNodeListImpl

Fields Summary
Constructors Summary
public NameNodeListImpl(NodeImpl rootNode, String tagName)
Constructor.

	super( rootNode, tagName );
    
Methods Summary
protected org.w3c.dom.NodenextMatchingElementAfter(org.w3c.dom.Node current)
Iterative tree-walker. When you have a Parent link, there's often no need to resort to recursion. NOTE THAT only Element nodes are matched since we're specifically supporting getElementsByTagName().

        
        Node next;
        while (current != null) {
            // Look down to first child.
            if (current.hasChildNodes()) {
                current = (current.getFirstChild());
            }
            
            // Look right to sibling (but not from root!)
            else if (current != rootNode && null != (next = current.getNextSibling())) {
                current = next;
            }
            
            // Look up and right (but not past root!)
            else {
                next = null;
                for (; current != rootNode; // Stop when we return to starting point
                     current = current.getParentNode()) {
                    
                    next = current.getNextSibling();
                    if (next != null)
                        break;
                }
                current = next;
            }
            
            // Have we found an Element with the right tagName?
            // ("*" matches anything.)
            if (current != rootNode && current != null
                && current.getNodeType() ==  Node.ELEMENT_NODE  ) {
                String name = ((ElementImpl) current).getAttribute( "name" );
                if ( name.equals("*") || name.equals(tagName))
                    return current;
            }
            
            // Otherwise continue walking the tree
        }
        
        // Fell out of tree-walk; no more instances found
        return null;