//serialize the node to SAX
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter( baos, UTF_8 );
IndentingXMLWriter xmlWriter = new IndentingXMLWriter( osw );
Properties outputProperties = new Properties();
outputProperties.setProperty(OutputKeys.ENCODING, "UTF-8");
if (indentLevel != null) {
outputProperties.setProperty(OutputKeys.INDENT, "yes");
outputProperties.setProperty(EXistOutputKeys.INDENT_SPACES, indentLevel);
} else {
outputProperties.setProperty(OutputKeys.INDENT, "no");
}
xmlWriter.setOutputProperties(outputProperties);
SAXSerializer sax = new SAXSerializer();
sax.setReceiver( xmlWriter );