if (enc == null) {
enc = "UTF-8";
}
// marshal root object back out to document in memory
IMarshallingContext mctx = bfact.createMarshallingContext();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
XMLOutputFactory ofact = XMLOutputFactory.newInstance();
XMLStreamWriter wrtr = ofact.createXMLStreamWriter(bos, enc);
mctx.setXmlWriter(new StAXWriter(bfact.getNamespaces(), wrtr));
mctx.marshalDocument(obj);
} catch (XMLStreamException e) {
throw new JiBXException("Error creating writer", e);
}
// compare with original input document