<foo>
<bar>
foobar
</bar>
</foo>
To implement the solution, please use the following snippet code to achieve the requirement:
To achieve this, we use JAX-RPC and following webservice endpoint:
in the method nodeToString() we are getting the XML as String:
@WebMethod()
public String sayHello(javax.xml.soap.SOAPElement message) {
System.out.println("**************************ENDPOINT**************************************************");
System.out.println("sayHello:" + message.toString());
System.out.println("sayHello:" + message.getClass());
printNodeToConsole(message);
String xml_str = nodeToString(message);
System.out.println("****************************XML**********************");
System.out.println(xml_str);
System.out.println("****************************XML**********************");
return "Here is the message: '" + message + "'";
}
private String nodeToString(Node node) {
StringWriter sw = new StringWriter();
try {
System.out.println("Start string conversion...");
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.transform(new DOMSource(node), new StreamResult(sw));
} catch (TransformerException te) {
System.out.println("nodeToString Transformer Exception");
}
System.out.println("end string conversion...");
return sw.toString();
}
There is a workaround escaping the XML with CDATA or XML entities < >
but the solution would be to use javax.xml.soap.SOAPElement as parameter of the webservice endpoint