Java XML Document Format prettyPrint(Document doc, String programID, String xmlTraDestinationFolderPath)

Here you can find the source of prettyPrint(Document doc, String programID, String xmlTraDestinationFolderPath)

Description

pretty Print

License

Open Source License

Declaration

public static final void prettyPrint(Document doc, String programID,
            String xmlTraDestinationFolderPath) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.FileWriter;

import java.io.Writer;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;

public class Main {
    public static final void prettyPrint(Document doc, String programID,
            String xmlTraDestinationFolderPath) throws Exception {

        Transformer tf = TransformerFactory.newInstance().newTransformer();
        tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
                "2");
        tf.setOutputProperty(OutputKeys.INDENT, "yes");
        Writer out = new FileWriter(new File(xmlTraDestinationFolderPath
                + programID.replaceAll("_", "-") + ".xml"));
        tf.transform(new DOMSource(doc), new StreamResult(out));

    }// w  w w. j  av  a 2 s  . c om
}

Related

  1. formatXML(Document xml, Document xsl)
  2. formatXML(Document xml, Document xsl, URIResolver resolver, Writer output)
  3. pretty(Document document, OutputStream outputStream, int indent)
  4. prettyFormat(Document doc)
  5. prettyPrint(Document doc)
  6. prettyPrint(final Document aNode)
  7. prettyPrintXml(Document doc)
  8. prettyPrintXml(Document document)
  9. prettyPrintXMLDocument(Node node)