All pastes #128132 Raw Edit

Stuff

public text v1 · immutable
·published 2006-08-12 19:22 UTC
rendered paste body
public static Document createDomDocument ()
	{
		try {
			DocumentBuilder builder = DocumentBuilderFactory.newInstance ()
			        .newDocumentBuilder ();
			Document doc = builder.newDocument ();
			return doc;
		} catch (ParserConfigurationException e) {
		}
		return null;
	}

	public static void writeXmlFile (Document doc, String filename)
	{
		try {
			// Prepare the DOM document for writing
			Source source = new DOMSource (doc);

			// Prepare the output file
			File file = new File (filename);
			Result result = new StreamResult (file);

			// Write the DOM document to the file
			Transformer xformer = TransformerFactory.newInstance ()
			        .newTransformer ();
			xformer.transform (source, result);
		} catch (TransformerConfigurationException e) {
		} catch (TransformerException e) {
		}
	}