Method to preetyPrint Document in java

Posted on by Kim

public static void write(org.dom4j.Document document) {
        try {
            // Pretty print the document to System.out
            org.dom4j.io.OutputFormat format = org.dom4j.io.OutputFormat.createPrettyPrint();
            org.dom4j.io.XMLWriter writer = new org.dom4j.io.XMLWriter(new FileWriter("C:\\output.xml"), format);
            writer.write(document);
            writer.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Nice framework for testing (equals) xml: XmlUnit

1 comments:

dontcare says:

You might also want to look at vtd-xml, the next generation XML processing model that is far more powerful than DOM and SAX

http://vtd-xml.sf.net