use of org.dom4j.io.OutputFormat in project bw-calendar-engine by Bedework.
the class XmlTidy method main.
/**
* @param args
* @throws Exception
*/
public static void main(final String[] args) throws Exception {
String text = FileUtils.readFileToString(new File(args[0]));
OutputFormat format = OutputFormat.createPrettyPrint();
format.setTrimText(false);
// XMLWriter writer = new XMLWriter(System.out, format);
XMLWriter writer = new XMLWriter(new FileOutputStream(args[1]), format);
writer.write(DocumentHelper.parseText(text));
}
use of org.dom4j.io.OutputFormat in project tutorials by eugenp.
the class Dom4JParser method generateNewDocument.
public void generateNewDocument() {
try {
Document document = DocumentHelper.createDocument();
Element root = document.addElement("XMLTutorials");
Element tutorialElement = root.addElement("tutorial").addAttribute("tutId", "01");
tutorialElement.addAttribute("type", "xml");
tutorialElement.addElement("title").addText("XML with Dom4J");
tutorialElement.addElement("description").addText("XML handling with Dom4J");
tutorialElement.addElement("date").addText("14/06/2016");
tutorialElement.addElement("author").addText("Dom4J tech writer");
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(new FileWriter(new File("src/test/resources/example_dom4j_new.xml")), format);
writer.write(document);
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.dom4j.io.OutputFormat in project application by collectionspace.
the class NullResolver method serializeToBytes.
/**
* Simple serializer helper
* @param doc
* @return
* @throws IOException
*/
static byte[] serializeToBytes(Document doc) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setExpandEmptyElements(true);
outformat.setNewlines(true);
outformat.setIndent(false);
XMLWriter writer = new XMLWriter(out, outformat);
writer.write(doc);
writer.flush();
out.close();
return out.toByteArray();
}
use of org.dom4j.io.OutputFormat in project openmeetings by apache.
the class XmlExport method toXml.
public static void toXml(Writer out, Document doc) throws Exception {
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setIndentSize(1);
outformat.setIndent("\t");
outformat.setEncoding(UTF_8.name());
XMLWriter writer = new XMLWriter(out, outformat);
writer.write(doc);
writer.flush();
out.flush();
out.close();
}
use of org.dom4j.io.OutputFormat in project eclipse-cs by checkstyle.
the class XMLUtil method toByteArray.
/**
* Creates a pretty printed representation of the document as a byte array.
*
* @param document
* the document
* @return the document as a byte array (UTF-8)
* @throws IOException
* Exception while serializing the document
*/
public static byte[] toByteArray(Document document) throws IOException {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(512);
// Pretty print the document to System.out
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(byteOut, format);
writer.write(document);
return byteOut.toByteArray();
}
Aggregations