StAXOMBuilder builder = new StAXOMBuilder(root.getXMLStreamReader());
OMDocument omDocument = builder.getDocument();
Iterator it = omDocument.getChildren();
while (it.hasNext()) {
OMNode omNode = (OMNode) it.next();
omNode.serializeAndConsume(xmlwriter);
}
xmlwriter.flush();
String result = writer.toString();
// We can't test for equivalence because the underlying OMSourceElement is
// changed as it is serialized. So I am testing for an internal value.