Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

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.Document;

public class Main {
    private static final String ENCODING = "UTF-8";
    private static final String INDENT = "yes";

    public static synchronized boolean update(String sourceXML, Document doc) {
        try {
            Transformer tf = TransformerFactory.newInstance().newTransformer();
            tf.setOutputProperty(OutputKeys.ENCODING, ENCODING);
            tf.setOutputProperty(OutputKeys.INDENT, INDENT);
            Writer out = new FileWriter(new File(sourceXML));
            tf.transform(new DOMSource(doc), new StreamResult(out));
            return true;
        } catch (TransformerException | IOException e) {
            e.printStackTrace();
        }
        return false;
    }
}