import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
-import org.apache.xalan.serialize.DOMSerializer;
-import org.apache.xalan.serialize.SerializerToXML;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
private XMLHelper() {}
- public static DOMSerializer createDOMSerializer(Writer writer)
- throws IOException {
-// XMLSerializer serializer = new XMLSerializer(writer, createOutputFormat());
-// return serializer.asDOMSerializer();
- SerializerToXML serializer = new SerializerToXML();
- serializer.setWriter(writer);
- return serializer.asDOMSerializer();
- }
-
- public static DOMSerializer createDOMSerializer(OutputStream stream)
- throws IOException {
-// XMLSerializer serializer = new XMLSerializer(stream, createOutputFormat());
-// return serializer.asDOMSerializer();
- SerializerToXML serializer = new SerializerToXML();
- serializer.setOutputStream(stream);
- return serializer.asDOMSerializer();
- }
-// private static OutputFormat createOutputFormat() {
-// OutputFormat format = new OutputFormat();
-// format.setIndenting(true);
-// format.setLineWidth(80);
-// return format;
-// }
-
public static Document createEmptyDocument() throws ParserConfigurationException {
DocumentBuilder builder = createDocumentBuilder();
return builder.newDocument();
public static void write(Writer writer, Document document)
throws IOException {
- createDOMSerializer(writer).serialize(document);
+ writer.write(XMLRenderer.render(document));
}
public static void write(OutputStream stream, Document document)
throws IOException {
- createDOMSerializer(stream).serialize(document);
+ stream.write(XMLRenderer.render(document).getBytes());
}
}