Java XML Format prettyXmlPrint(Node xml, OutputStream out)

Here you can find the source of prettyXmlPrint(Node xml, OutputStream out)

Description

pretty Xml Print

License

Open Source License

Declaration

public static final void prettyXmlPrint(Node xml, OutputStream out)
            throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *                       I N T E L   C O R P O R A T I O N
 * /*w w w .j av  a 2 s  . c  o  m*/
 *  Functional Group: Fabric Viewer Application
 * 
 *  File Name: AppDataUtils.java
 * 
 *  Archive Source: $Source$
 * 
 *  Archive Log: $Log$
 *  Archive Log: Revision 1.18  2015/08/17 18:49:06  jijunwan
 *  Archive Log: PR 129983 - Need to change file header's copyright text to BSD license txt
 *  Archive Log: - change backend files' headers
 *  Archive Log:
 *  Archive Log: Revision 1.17  2015/06/10 19:36:45  jijunwan
 *  Archive Log: PR 129153 - Some old files have no proper file header. They cannot record change logs.
 *  Archive Log: - wrote a tool to check and insert file header
 *  Archive Log: - applied on backend files
 *  Archive Log:
 * 
 *  Overview:
 * 
 *  @author: Fernando Fernandez
 * 
 ******************************************************************************/

import java.io.OutputStream;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Node;

public class Main {
    public static final void prettyXmlPrint(Node xml, OutputStream out)
            throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.transform(new DOMSource(xml), new StreamResult(out));
    }
}

Related

  1. prettyPrintXML(String xml)
  2. prettyXml(final String xml)
  3. prettyXml(String xml)
  4. prettyXml(String xml)
  5. prettyXml(String xml)
  6. print(Element elm, OutputStream out)
  7. print(File file)
  8. print(Node node)
  9. print(Node node)