OutputStreamWriter out = null;
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream(5000);
out = new OutputStreamWriter(bout, options.getEncoding());
IBindingFactory bf = BindingDirectory.getFactory(JibxBinding.class);
IMarshallingContext mctx = bf.createMarshallingContext();
mctx.setIndent(1, null, '\t');
mctx.marshalDocument(root, options.getEncoding(), null, out);
return bout.toByteArray();
} finally {
if(out!=null) try { out.close(); } catch(Exception ex) {}
}