Example usage for org.dom4j.io XMLWriter startDocument

List of usage examples for org.dom4j.io XMLWriter startDocument

Introduction

In this page you can find the example usage for org.dom4j.io XMLWriter startDocument.

Prototype

public void startDocument() throws SAXException 

Source Link

Usage

From source file:org.safehaus.penrose.studio.util.ApplicationConfig.java

License:Open Source License

public void save(File file) throws Exception {
    FileWriter fw = new FileWriter(file);
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setTrimText(false);/*from www  . ja v a 2s . c o  m*/

    XMLWriter writer = new XMLWriter(fw, format);
    writer.startDocument();
    writer.write(toElement());
    writer.close();
}

From source file:org.snipsnap.util.JDBCDatabaseExport.java

License:Open Source License

/**
 * Store snips and users from the SnipSpace to an xml document into a stream.
 * @param out outputstream to write to/*from  w  ww .  j av a 2s  . c  o m*/
 */
public static void store(OutputStream out, String appOid, Connection connection) {
    try {
        OutputFormat outputFormat = new OutputFormat();
        outputFormat.setEncoding("UTF-8");
        outputFormat.setNewlines(true);

        XMLWriter xmlWriter = new XMLWriter(out, outputFormat);
        xmlWriter.startDocument();
        Element root = DocumentHelper.createElement("snipspace");
        xmlWriter.writeOpen(root);

        //      storeUsers(xmlWriter, connection);
        storeSnips(xmlWriter, appOid, connection);

        xmlWriter.writeClose(root);
        xmlWriter.endDocument();
        xmlWriter.flush();
        xmlWriter.close();
    } catch (Exception e) {
        System.err.println("JDBCDatabaseExport: error while writing document: " + e.getMessage());
    }
}

From source file:org.xwiki.store.serialization.xml.internal.AbstractXMLSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//from www  .  jav a2 s. c  om
 *
 * @see org.xwiki.store.filesystem.internal.XMLSerializer#serialize(T)
 */
public InputStream serialize(final R object) throws IOException {
    // This puts everything on the heap for now.
    // if size becomes a major problem, the alternitive is to fork over another thread
    // and use a PipedInputStream.
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

    final XMLWriter writer;
    try {
        // This should always be UTF-8 because it is a property of the serializer.
        final OutputFormat of = new OutputFormat(" ", true, "UTF-8");
        writer = new XMLWriter(baos, of);
        writer.startDocument();
    } catch (SAXException e) {
        throw new IOException("Could not open the XML writer.");
    }

    this.serialize(object, writer);

    try {
        writer.endDocument();
    } catch (SAXException e) {
        throw new IOException("Could not close the XML writer.");
    }

    return new ByteArrayInputStream(baos.toByteArray());
}