Java XML DOM Parse parseFileToXML(Transformer transformer, DOMSource source, File file)

Here you can find the source of parseFileToXML(Transformer transformer, DOMSource source, File file)

Description

Parse file to xml type

License

Open Source License

Parameter

Parameter Description
transformer a parameter
source a parameter
file a parameter

Exception

Parameter Description
FileNotFoundException an exception
TransformerException an exception

Declaration

public static void parseFileToXML(Transformer transformer, DOMSource source, File file)
        throws FileNotFoundException, TransformerException 

Method Source Code

//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);
    }
}

Related

  1. parse_XML_String_and_create_DOM(String xmlData)
  2. parseDom(InputStream byteArrayInputStream)
  3. parseDom(Reader reader)
  4. parseDOMConfigFile(String folderPath, String configFileName)
  5. parseDomFromFile(File doc)
  6. parseToDOM(InputStream stream)
  7. parseToDom(String content)
  8. parseXMLToDOM(String xml_str)