StringWriter buffer = new StringWriter();
SAXTransformerFactory tf = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
TransformerHandler hd = tf.newTransformerHandler();
StreamResult result = new StreamResult(buffer);
hd.setResult(result);
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
// Transform -> SAX event stream
SAXResult saxResult = new SAXResult(new NoKernelNamespaceSAXFilter(hd));