This example shows how to create a "squeezed" document, but one that will work in browsers even if the browser line length is limited. No newlines are included, no extra whitespace at all, except where it it required by {@link #setPreformattedTags(java.util.Set) setPreformattedTags}.
String testCrunch(String html) { StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setNewlines(false); format.setTrimText(true); format.setIndent(""); format.setXHTML(true); format.setExpandEmptyElements(false); format.setNewLineAfterNTags(20); org.dom4j.io.HTMLWriter writer = new HTMLWriter(sw, format); org.dom4j.Document document = DocumentHelper.parseText(html); writer.write(document); writer.flush(); return sw.toString(); }@author James Strachan @author Laramie Crocker @version $Revision: 1.21 $
|
|
|
|
|
|
|
|