currentElement = currentElement.getElement(state[currentDepth]); return currentElement;
ElementRef top = (ElementRef) stack.peek(); top.index++; next = next();
  public Element next()  {    previousItem = currentElement;    if (currentElement == null)      return null;    if (! currentElement.isLeaf())      {	++currentDepth;	if (currentDepth > state.length)	  {	    int[] newState = new int[state.length * 2];	    System.arraycopy(state, 0, newState, 0, state.length);	    state = newState;	  }	state[currentDepth] = 0;	currentElement = currentElement.getElement(0);	return currentElement;      }    while (currentDepth > 0)      {	// At a leaf, or done with a non-leaf's children, so go up a	// level.	--currentDepth;	currentElement = currentElement.getParentElement();	++state[currentDepth];	if (state[currentDepth] < currentElement.getElementCount())	  {	    currentElement = currentElement.getElement(state[currentDepth]);	    return currentElement;	  }      }    currentElement = null;    return currentElement;  }