private Node nextNode(Node x,XMLWriter xml){
  Node n, c;
  if ((c=x.getChild(0)) != null) {
  }
 else   if ((c=x.getNextSibling()) != null) {
    xml.end();
  }
 else {
    c=x.getParent();
    xml.end();
    while (c != null) {
      if ((n=c.getNextSibling()) != null) {
        c=n;
        xml.end();
        break;
      }
      c=c.getParent();
      xml.end();
    }
  }
  return c;
}

private Node nextNode ( Node x , XMLWriter xml ) { Node n , c ; if ( ( c = x . getChild ( 0 ) ) != null ) { } else if ( ( c = x . getNextSibling ( ) ) != null ) { xml . end ( ) ; } else { c = x . getParent ( ) ; xml . end ( ) ; while ( c != null ) { if ( ( n = c . getNextSibling ( ) ) != null ) { c = n ; xml . end ( ) ; break ; } c = c . getParent ( ) ; xml . end ( ) ; } } return c ; }
find the next node in the depth first iteration , closing off open branch tags as needed .
