Java XML Format print(File file)

Here you can find the source of print(File file)

Description

print

License

Open Source License

Declaration

public static void print(File file) throws Exception 

Method Source Code


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

import java.io.File;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class Main {
    public static void print(File file) throws Exception {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(new StreamSource(file), new StreamResult(System.out));
    }/*from   w  w w  . java  2  s  .com*/
}

Related

  1. prettyXml(String xml)
  2. prettyXml(String xml)
  3. prettyXml(String xml)
  4. prettyXmlPrint(Node xml, OutputStream out)
  5. print(Element elm, OutputStream out)
  6. print(Node node)
  7. print(Node node)
  8. print(Node node, OutputStream out)
  9. print(Node node, String encoding)