Example of the method storing a DOM tree into a file (see Homework 1)
The procedure utilizes a transformation we do not know yet. Let use it as a black box.
import java.io.File;
import java.io.IOException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
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 Uloha1 {
Document doc;
/**
* ***********************************************************************
* Method for a salary modification. If the person's salary is less then
* <code>minimum</code>, the salary will increased to
* <code>minimum>.
* No action is performed with the rest of persons.
*/
public void serializetoXML(File output) throws IOException, TransformerConfigurationException, TransformerException {
// We create new instance of a factory class.
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
// The input is the document placed in a memory
DOMSource source = new DOMSource(doc);
// The transformation output is the output file
StreamResult result = new StreamResult(output);
// Let's make the transformation
transformer.transform(source, result);
}
}