code: protected void beforeEndElement() {
          if (depth > 0 && stack[depth] == WROTE_MARKUP) { // but not data
              try {
                  writeNewLine(depth - 1);
              } catch (Exception ignored) {
                  ignored.printStackTrace();
              }
          }
      }
docs: Prepare to end an element, by writing a new line and indentation.