File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes javax.xml.soap.SOAPElement  addTextNode(String) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "javax.xml.soap.SOAPElement  addTextNode(String)" Watch "javax.xml.soap.SOAPElement  addTextNode(String)" New topic

javax.xml.soap.SOAPElement addTextNode(String)

ahmad namini
Ranch Hand

Joined: Aug 29, 2002
Posts: 52
I have a String which has xml markup within it. I need to append this String as XML encoded text within a SOAP Body. javax.xml.soap.SOAPElement has the addTextNode(String) method but all the markup is encoded with escape sequences instead.
Does anyone know how to encode this properly?

-Ahmad<br />Sun Certified Java Developer (SCJD)<br />Sun Certified Java Programmer (SCJP)<p>"You got to be careful if you don't know where you're going, because you might not get there." -Yogi Berra
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
If you want to add the string "as XML" instead of "as a string", you need to use addChildElement(...).

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
ahmad namini
Ranch Hand

Joined: Aug 29, 2002
Posts: 52
Thanks for the response Lasse.
I have indeed tried addChildElement(). However, this method assumes that the string is the tag name, and thus adds < and /> at the beginning and end of my string.
I did in fact solve my problem by essentially writing a recursive deep copy method which starts at the root element and appends each child element and its child element and so forth with its attributes, namespaces, and content.
Works great. You would think that a nice method would be provided within the SAAJ or the JAXM libraries. If there is, I couldn't find it.
I agree. Here's the link:
subject: javax.xml.soap.SOAPElement addTextNode(String)
It's not a secret anymore!