I am using javax.xml.soap implementation to create the soap elements.
When i add a custom Namespace and keep adding the elements in that namespace,
then the custom namespace declaration is repeated.
public void testquick() throws Exception { MessageFactory msgfactory = MessageFactory.newInstance(); SOAPFactory factory = SOAPFactory.newInstance();
SOAPMessage outputmsg = msgfactory.createMessage();
SOAPBody bodyout = outputmsg.getSOAPPart().getEnvelope().getBody();
Name n = factory.createName("HelloWorld","env", "http://helloworld.com");
SOAPBodyElement entry = bodyout.addBodyElement(n);
n = factory.createName("code","env", "http://helloworld.com");
SOAPElement element = factory.createElement(n);
entry.addChildElement(element);
if (outputmsg != null) { if (outputmsg.saveRequired()) { outputmsg.saveChanges(); }
outputmsg.writeTo(System.out); } }
Output is:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<env:HelloWorld xmlns:env="http://helloworld.com">
<env:code xmlns:env="http://helloworld.com"/> <-- see the Namespace declaration is repeated
</env:HelloWorld>
</soapenv:Body>
Ideal Output is
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<env:HelloWorld xmlns:env="http://helloworld.com">
<env:code />
</env:HelloWorld>
</soapenv:Body>
I personally feel this is because of the following code in MessageElement
public MessageElement(String localPart, String prefix, String namespace)
{
this.namespaceURI = namespace;
this.name = localPart;
this.prefix = prefix;
addMapping(new Mapping(namespace, prefix)); <-- Adding prefix for each declaration without checking whether parent element is in same namespace.
}
Note : Please suggest a solution (If any) using only javax.xml.soap interfaces. I want to keep the generic interfaces and not make direct calls to MessageElements.
Smith
_________________________________________________________________
Dress up your desktop! Get the best wallpapers. http://server1.msn.co.in/msnchannels/Entertainment/wallpaperhome.asp Just click here!