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?