Here you can find the source of parseFileToXML(Transformer transformer, DOMSource source, File file)
Parameter | Description |
---|---|
transformer | a parameter |
source | a parameter |
file | a parameter |
Parameter | Description |
---|---|
FileNotFoundException | an exception |
TransformerException | an exception |
public static void parseFileToXML(Transformer transformer, DOMSource source, File file) throws FileNotFoundException, TransformerException
//package com.java2s; //License from project: Open Source License import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.*; public class Main { /**/*w ww . j a v a2 s. c o m*/ * Parse file to xml type * * @param transformer * @param source * @param file * @throws FileNotFoundException * @throws TransformerException */ public static void parseFileToXML(Transformer transformer, DOMSource source, File file) throws FileNotFoundException, TransformerException { transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); PrintWriter pw = new PrintWriter(file); StreamResult streamResult = new StreamResult(pw); transformer.transform(source, streamResult); } }