1 package com.quantum.util.xml;
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.OutputStream;
8 import javax.xml.parsers.DocumentBuilder;
9 import javax.xml.parsers.DocumentBuilderFactory;
10 import javax.xml.parsers.FactoryConfigurationError;
11 import javax.xml.parsers.ParserConfigurationException;
13 import org.w3c.dom.Document;
14 import org.xml.sax.SAXException;
18 * <p>This class constructs a pretty-printing XML Serializer
22 public class XMLHelper {
24 private XMLHelper() {}
26 public static Document createEmptyDocument() throws ParserConfigurationException {
27 DocumentBuilder builder = createDocumentBuilder();
28 return builder.newDocument();
31 public static Document createFromInputStream(InputStream stream)
32 throws IOException, SAXException, ParserConfigurationException {
33 DocumentBuilder builder = createDocumentBuilder();
34 return builder.parse(stream);
37 private static DocumentBuilder createDocumentBuilder()
38 throws FactoryConfigurationError, ParserConfigurationException {
39 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
40 return factory.newDocumentBuilder();
43 public static void write(Writer writer, Document document)
45 writer.write(XMLRenderer.render(document));
48 public static void write(OutputStream stream, Document document)
50 stream.write(XMLRenderer.render(document).getBytes());