AxiomUtils { public static Document toDocument(SOAPEnvelope envelope) { try { if (envelope instanceof Element) { return ((Element) envelope).getOwnerDocument(); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); envelope.build(); envelope.serialize(bos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance(); documentBuilderFactory.setNamespaceAware(true); return documentBuilderFactory.newDocumentBuilder().parse(bis); } } catch (Exception ex) { throw new IllegalArgumentException("Error in converting SOAP Envelope to Document", ex); } }  static OMNamespace toNamespace(QName qName, OMElement resolveElement); static String toLanguage(Locale locale); static Locale toLocale(String language); static void removeContents(OMContainer container); static Document toDocument(SOAPEnvelope envelope); static SOAPEnvelope toEnvelope(Document document);  }
@Test @SuppressWarnings("Since15") public void testToDocument() throws Exception { Resource resource = new ClassPathResource("org/springframework/ws/soap/soap11/soap11.xml"); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource)); SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(resource.getInputStream(), null); SOAPMessage soapMessage = builder.getSOAPMessage(); Document result = AxiomUtils.toDocument(soapMessage.getSOAPEnvelope()); assertXMLEqual("Invalid document generated from SOAPEnvelope", expected, result); }