FileDocCategorySizeDatePackage
NameNodeListImpl.javaAPI DocApache Xerces 3.0.13470Fri Sep 14 20:33:56 BST 2007org.apache.html.dom

NameNodeListImpl

public class NameNodeListImpl extends org.apache.xerces.dom.DeepNodeListImpl implements NodeList
This class implements the DOM's NodeList behavior for HTMLDocuemnt.getElementsByName().
xerces.internal
version
$Id: NameNodeListImpl.java 447255 2006-09-18 05:36:42Z mrglavas $
since
PR-DOM-Level-1-19980818.
see
DeepNodeListImpl

Fields Summary
Constructors Summary
public NameNodeListImpl(org.apache.xerces.dom.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;