Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;

import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

public class Main {
    public static synchronized void writeXmlFile(String xmlFile, Document document) throws Exception {
        // transform the document to the file
        TransformerFactory xformFactory = TransformerFactory.newInstance();
        Transformer idTransformer = xformFactory.newTransformer();
        idTransformer.setOutputProperty("indent", "yes");
        Source input = new DOMSource(document);
        Result output = new StreamResult(new File(xmlFile));
        idTransformer.transform(input, output);
        /*
         OutputFormat format = new OutputFormat();
         format.setLineSeparator(LineSeparator.Unix);
         format.setIndenting(true);
         format.setLineWidth(0);
         format.setPreserveSpace(true);
         XMLSerializer ser = new XMLSerializer(new FileWriter(xmlFile),
         format);
         ser.asDOMSerializer();
         ser.serialize(document);
         */
        return;
    }
}