Here you can find the source of printDOMTree(Node node, PrintWriter out, String docType, String copyright)
Parameter | Description |
---|---|
node | a parameter |
out | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void printDOMTree(Node node, PrintWriter out, String docType, String copyright) throws IOException
//package com.java2s; import java.io.IOException; import java.io.PrintWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { /**/*from www. ja v a2s .co m*/ * Debugging method for printing out the DOM Tree * Prints the specified node, recursively. * * @param node * @param out * @throws IOException */ public static void printDOMTree(Node node, PrintWriter out, String docType, String copyright) throws IOException { try { Transformer transformer = TransformerFactory.newInstance() .newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty( "{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); out.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); if (copyright != null) { out.print(copyright); } if (docType != null) { out.print(docType); } // transformer.setParameter(entityName, entityRef ); // transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, XLIFF_PUBLIC_NAME); transformer.transform(new DOMSource(node), new StreamResult(out)); } catch (TransformerException te) { throw new IOException(te.getMessage()); } // out.close(); } }