PiRSquared17 / tomproject

Automatically exported from code.google.com/p/tomproject
0 stars 0 forks source link

writeDomToStream #72

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hight priority to use in current project.

    // This method writes a DOM document to a stream
    private static void writeDomToStream(Document doc, PrintStream stream) 
throws Exception {

    // Prepare the DOM document for writing
    Source source = new DOMSource(doc);

    // Prepare the output stream
    Result result = new StreamResult(stream);

    // Write the DOM document to the file
    Transformer xformer = 
TransformerFactory.newInstance().newTransformer();
    xformer.transform(source, result);

    }

Original issue reported on code.google.com by brito....@gmail.com on 29 Mar 2010 at 2:26

GoogleCodeExporter commented 9 years ago
add to TomXmlUtils

Original comment by brito....@gmail.com on 29 Mar 2010 at 2:28

GoogleCodeExporter commented 9 years ago
if Document extends Node, why throws an exception when trying to use
com.sun.org.apache.xml.internal.security.utils.XMLUtils.outputDOM(Node 
contextNode, 
OutputStream os)?

Original comment by brito....@gmail.com on 29 Mar 2010 at 2:35

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Improved method:

    // This method writes a DOM document to a stream
    public static void outputDOM(Document doc, PrintStream stream)
        throws TransformerFactoryConfigurationError, TransformerException {

    // Prepare the DOM document for writing
    Source source = new DOMSource(doc);
    // Prepare the output stream
    Result result = new StreamResult(stream);

    // Write the DOM document to the file
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    xformer.setOutputProperty(OutputKeys.INDENT, "yes");
    xformer.transform(source, result);

    }

Original comment by brito....@gmail.com on 29 Mar 2010 at 6:10

GoogleCodeExporter commented 9 years ago

Original comment by brito....@gmail.com on 9 Apr 2010 at 1:18