You can use doc.createTextNode and use a workaround (long) for escaped characters.
SOAPMessage msg = messageContext.getMessage ();
header.setTextContent (seched);
Then use
Source src = msg.getSOAPPart().getContent();
Convert to string to get content
TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer. setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StreamResult result1 = new StreamResult(new StringWriter()); transformer.transform(src, result1);
Replace string special characters
String xmlString = result1.getWriter().toString() .replaceAll("<", "<"). replaceAll(">", ">"); System.out.print(xmlString);
oposite string for dom with fixed escaped characters
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlString)); Document doc = db.parse(is); Source src123 = new DOMSource(doc);
Then install it back into the message with soap msg.getSOAPPart().setContent(src123);
source share