package com.quantum.util.xml; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Writer; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; /** *
This class constructs a pretty-printing XML Serializer * * @author BC */ public class XMLHelper { private XMLHelper() {} public static Document createEmptyDocument() throws ParserConfigurationException { DocumentBuilder builder = createDocumentBuilder(); return builder.newDocument(); } public static Document createFromInputStream(InputStream stream) throws IOException, SAXException, ParserConfigurationException { DocumentBuilder builder = createDocumentBuilder(); return builder.parse(stream); } private static DocumentBuilder createDocumentBuilder() throws FactoryConfigurationError, ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); return factory.newDocumentBuilder(); } public static void write(Writer writer, Document document) throws IOException { writer.write(XMLRenderer.render(document)); } public static void write(OutputStream stream, Document document) throws IOException { stream.write(XMLRenderer.render(document).getBytes()); } }