How do you add XML prolog in javax.xml.soap.SOAPBody



I am trying to send an XML document via SOAP to a server that requires the payload XML to contain an XML prolog e.g., <?xml version="1.0" encoding="utf-8" ?>. The following is very similar to the code I'm using:



SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = getSoapMessage().getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("SOAP-ENV", "http://ift.tt/sVJIaE");
soapHeader = envelope.getHeader();
soapBody = envelope.getBody();

soapHeader.detachNode();
SOAPBodyElement bodyElement = soapBody.addBodyElement(getEnvelope().createName("my_element_name"));
bodyElement.addAttribute(getEnvelope().createName("my_attribute_name"), "my_attribute_value");
bodyElement.addChildElement("my_child_element");
...

No comments:

Post a Comment