I want to convert SOAPBody to String. What is the best way to do it? Should i first convert it to xml and then convert it into String or we can jsut convert it into String.<
You do not need to convert SOAPBody
to XML
, because it implements org.w3c.dom.Element
interface, thus this is already a valid XML
object.
You can use org.w3c.dom.ls
package to achieve your goal:
String xmlAsString = null;
Element element = what-ever-element;
DOMImplementationLS domImplementationLS = (DOMImplementationLS)element.getOwnerDocument().getImplementation().getFeature("LS", "3.0");
LSSerializer serializer = domImplementationLS.createLSSerializer();
xmlAsString = serializer.writeToString(element);
You can play with serializer.getDomConfig().setParameter(....)
to configure the serializer.