String () { StringBuilder stringForm = new StringBuilder() .append("[Document: "); DocType docType = getDocType(); if (docType != null) { stringForm.append(docType) .append(", "); } else { stringForm.append(" No DOCTYPE declaration, "); } Element rootElement = hasRootElement() ? getRootElement() : null; if (rootElement != null) { stringForm.append("Root is ") .append(rootElement); } else { stringForm.append(" No root element"); // shouldn't happen } stringForm.append("]"); return stringForm.toString(); }