uctx.setDocument(new FileInputStream(file), null);
Object object = uctx.unmarshalElement();
String encoding = ((UnmarshallingContext)uctx).getInputEncoding();
// marshal object back out to document in memory
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);