Getting Raw XML From SOAPMessage in Java

前端 未结 9 1947
醉梦人生
醉梦人生 2020-12-02 06:41

I\'ve set up a SOAP WebServiceProvider in JAX-WS, but I\'m having trouble figuring out how to get the raw XML from a SOAPMessage (or any Node) object. Here\'s a sample of t

9条回答
  •  天涯浪人
    2020-12-02 07:02

    If you need formatting the xml string to xml, try this:

    String xmlStr = "your-xml-string";
    Source xmlInput = new StreamSource(new StringReader(xmlStr));
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    transformer.transform(xmlInput,
            new StreamResult(new FileOutputStream("response.xml")));
    

提交回复
热议问题