public void printElement(Element element){
  boolean hasChildren=element.hasChildNodes();
  startTag(element,hasChildren);
  if (hasChildren) {
    boolean prevWasText=false;
    NodeList children=element.getChildNodes();
    for (int i=0; i < children.getLength(); i++) {
      Node node=children.item(i);
      if (node instanceof Element) {
        if (!prevWasText) {
          println();
        }
        printElement((Element)children.item(i));
        prevWasText=false;
      }
 else       if (node instanceof Text) {
        print(getEscaped(node.getNodeValue()));
        prevWasText=true;
      }
    }
    if (!prevWasText) {
      println();
    }
    endTag(element);
  }
}

public void printElement ( Element element ) { boolean hasChildren = element . hasChildNodes ( ) ; startTag ( element , hasChildren ) ; if ( hasChildren ) { boolean prevWasText = false ; NodeList children = element . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { Node node = children . item ( i ) ; if ( node instanceof Element ) { if ( ! prevWasText ) { println ( ) ; } printElement ( ( Element ) children . item ( i ) ) ; prevWasText = false ; } else if ( node instanceof Text ) { print ( getEscaped ( node . getNodeValue ( ) ) ) ; prevWasText = true ; } } if ( ! prevWasText ) { println ( ) ; } endTag ( element ) ; } }
prints the given element .
