// Get the root
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments.getRootPartInputStream(), "UTF-8");
OMElement root = builder.getDocumentElement();
StringWriter xmlWriter = new StringWriter();
root.serialize(xmlWriter);
// Serialize the message using the legacy behavior (order by content id)
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding("utf-8");
format.setDoingSWA(true);