final XMLMapper mapper = XMLMapper.Factory.create();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final BufferedOutputStream bos = new BufferedOutputStream(baos);
final XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(bos);
try {
mapper.deparseDocument(new RootElementWriter(element, content), writer);
}
catch (XMLStreamException e) {
// Dump some diagnostics
stdout.println("XML Content that was written prior to exception:");
stdout.println(writer.toString());