private void next(String name) throws NoSuchElementException {
   switch (state) {
     case STATE_BEFORE:
       // We are before the first sibling => go to first sibling.
       state = STATE_AT;
       break;
     case STATE_AT:
       // We are at a sibling => go to next sibling if any,
       //                        go after current if current is the last.
       Element t = DOMUtil.nextSiblingElement(__current);
       if (t != null) {
         __current = t;
       } else {
         // Changed 20011001: should never go STATE_AFTER, all calls
         // to next are followed by a call to current() which will then throw
         // an exception =>
         // TODO: remove STATE_AFTER completely
         // state = STATE_AFTER;
         throw new NoSuchElementException("No more sibling elements.");
       }
       break;
     case STATE_AFTER:
       // We are after the last sibling => this method call is "illegal".
       throw new NoSuchElementException("No more sibling elements.");
     case STATE_IN_EMPTY_SET:
       // We in the child set of an element without children => this method call is "illegal".
       throw new NoSuchElementException("No elements.");
     default:
       throw new RuntimeException("Illegal state.");
   }
   if (name != null && !name.equals(DOMUtil.getLocalName(__current))) {
     throw new NoSuchElementException(
         "Not at element " + name + ": " + __current.getNodeName() + ".");
   }
 }
  private String text(String name) throws NoSuchElementException {
    was_CDATA = false;
    Element t = current();

    NodeList l = t.getChildNodes();

    if (name != null && !name.equals(DOMUtil.getLocalName(t))) {
      throw new NoSuchElementException("Not at element " + name + ": " + t.getNodeName() + ".");
    }

    if (l.getLength() == 0) {
      return null;
    }
    StringBuffer s = new StringBuffer();
    was_CDATA = true;
    for (int i = 0; i < l.getLength(); i++) {
      Node n = l.item(i);
      short nt = n.getNodeType();
      if (nt != Node.TEXT_NODE && nt != Node.CDATA_SECTION_NODE) {
        throw new NoSuchElementException("Not at a Text/CDATA element: " + t.getNodeName() + ".");
      }
      if (nt == Node.TEXT_NODE) {
        was_CDATA = false;
      }
      s.append(n.getNodeValue());
    }
    return s.toString();
  }
  /**
   * Check if the next sibling of <a href="#last">&quot;last visited element&quot;</a> has local
   * name <code><i>name</i></code> (and if exists at all).
   *
   * @return true iff the <a href="#last">&quot;last visited element&quot;</a> has more siblings,
   *     and the next sibling has local name <code><i>name</i></code>.
   */
  public boolean hasNext(String name) {
    Element next =
        (state == STATE_BEFORE)
            ? __current
            : (state == STATE_AT) ? DOMUtil.nextSiblingElement(__current) : null;

    return next != null && DOMUtil.getLocalName(next).equals(name);
  }