Soapmessage add namespace

Viewed 381

I am trying to create a soap message that will have two namespaces using javax.xml.soap.* But the the message being created does not add the second namespace. I am not sure why it does not recognize the second addnamespacedeclaration statement.

Appreciate the help


package testsoapmsg;

    import java.io.FileOutputStream;

import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;

     

public class CreateeSoapMessage {
    public static void main(String[] args) {
        try{
            MessageFactory factory = MessageFactory.newInstance();
            SOAPMessage soapMsg = factory.createMessage();
            SOAPPart part = soapMsg.getSOAPPart();
            SOAPEnvelope envelope = part.getEnvelope();
            envelope.addNamespaceDeclaration("xmlns", "http://schemas.xmlsoap.org/soap/envelope/");
            envelope.addNamespaceDeclaration("xmlns", "http://ACORD.org/Standards/Life/2");
            SOAPHeader header = envelope.getHeader();
            SOAPBody body = envelope.getBody();
            QName childname = new QName("TxLife");
            SOAPElement txlife = body.addChildElement(childname);
            
              soapMsg.writeTo(System.out);
                FileOutputStream fOut = new FileOutputStream("SoapMessage.xml");
                soapMsg.writeTo(fOut);
                System.out.println();
                System.out.println("SOAP msg created");  
                
          }catch(Exception e){
              
                            e.printStackTrace();
              
                        }
              


    }

}

The output I get is

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><TxLife/></SOAP-ENV:Body></SOAP-ENV:Envelope>
SOAP msg created
0 Answers
Related