Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.*;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;

public class Main {
    public static void writeXMLFile(Node node, String filename) throws IOException {

        try {
            // Prepare the DOM document for writing
            DOMSource source = new DOMSource(node);
            // Prepare the output file

            StreamResult result = new StreamResult(filename);

            // Write the DOM document to the file
            Transformer xformer = TransformerFactory.newInstance().newTransformer();
            xformer.transform(source, result);

        } catch (TransformerConfigurationException e) {
            throw new IOException();
        } catch (TransformerException e) {
            throw new IOException();
        }
    }
}