IMarshallingContext mctx = factory.createMarshallingContext();
mctx.setIndent(2);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
mctx.setOutput(bos, "UTF-8");
((IMarshallable)object).marshal(mctx);
mctx.endDocument();
// compare with original input document
InputStreamReader brdr = new InputStreamReader
(new ByteArrayInputStream(bos.toByteArray()), "UTF-8");
InputStreamReader frdr = new InputStreamReader(new FileInputStream(file), encoding);