Here you can find the source of serialize(Node node, File outdir, String fileName)
Parameter | Description |
---|---|
node | The DOM node to be serialised. |
outdir | The directory into which the file is to be serialised. |
fileName | The name of the file. |
Parameter | Description |
---|---|
ConfigurationException | Unable to serialise the node. |
public static void serialize(Node node, File outdir, String fileName) throws ConfigurationException
//package com.java2s; // License as published by the Free Software Foundation; either import java.io.File; import java.io.OutputStream; import javax.naming.ConfigurationException; 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.Node; public class Main { /**//from w w w . j a v a 2 s . co m * Serialize the supplied DOM node to the specified file in the specified output directory. * @param node The DOM node to be serialised. * @param outdir The directory into which the file is to be serialised. * @param fileName The name of the file. * @throws ConfigurationException Unable to serialise the node. */ public static void serialize(Node node, File outdir, String fileName) throws ConfigurationException { serialize(node, new StreamResult(new File(outdir, fileName))); } public static void serialize(Node node, OutputStream out) throws ConfigurationException { serialize(node, new StreamResult(out)); } /** * Serialize the supplied DOM node to the supplied DOM StreamResult instance. * @param node The DOM node to be serialised. * @param streamRes The StreamResult into which the node is to be serialised. * @throws ConfigurationException Unable to serialise the node. */ public static void serialize(Node node, StreamResult streamRes) throws ConfigurationException { serialize(node, streamRes, false); } /** * Serialize the supplied DOM node to the supplied DOM StreamResult instance. * @param node The DOM node to be serialised. * @param streamRes The StreamResult into which the node is to be serialised. * @param omitXmlDecl Omit the XML declaration. * @throws ConfigurationException Unable to serialise the node. */ public static void serialize(Node node, StreamResult streamRes, boolean omitXmlDecl) throws ConfigurationException { DOMSource domSource = new DOMSource(node); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); // There's a bug in Java 5 re this code (formatting). // See http://forum.java.sun.com/thread.jspa?threadID=562510&start=0 and it explains the // whys of the following code. // transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, (omitXmlDecl ? "yes" : "no")); transformer.transform(domSource, streamRes); } catch (Exception e) { throw new ConfigurationException("Failed to serialize ESB Configuration Document instance."); } } }