Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set <?xml version="1.0" encoding="UTF-8"?> in a SOAP message

843834Nov 29 2002 — edited Dec 7 2002
Hi I am using the following code to make a simple SOAP message!But when i see the generated XML I can not see the

<?xml version="1.0" encoding="UTF-8"?>

How I will be able to add this line?
   MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage message = mf.createMessage();
    SOAPPart sp = message.getSOAPPart();
    SOAPEnvelope envelope = sp.getEnvelope();
    SOAPHeader header = envelope.getHeader();
    SOAPBody body = envelope.getBody();
    SOAPHeaderElement headerElement = header.addHeaderElement(envelope.createName("SessionID","m","Some-URL"));
    headerElement.addAttribute(envelope.createName("value"),"2123123");
    SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName("StartSession", "m","Some-URL"));
    bodyElement.addChildElement("username").addTextNode("TestUser");
    message.saveChanges();
    message.writeTo(new FileOutputStream(new File("c:/test.xml")));
    message.writeTo(System.out);
 
The strange thing is that when i use a transformer to read the generated XML from the file and then save it again in another file..it adds the
<?xml version="1.0" encoding="UTF-8"?>

Any hints?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 4 2003
Added on Nov 29 2002
5 comments
1,484 views