How to convert SOAPBody to String

后端 未结 3 470
梦如初夏
梦如初夏 2020-12-11 01:02

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.<

3条回答
  •  北海茫月
    2020-12-11 01:48

    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.

提交回复
热议问题