Details
Description
This code:
public static void main(String[] args) {
String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<registryInfo xmlns=\"urn:uddi-org:api\">" +
"<property xmlns=\"urn:uddi-org:api_v2\" name=\"operatorEmailAddress\" value=\"admin@juddi.org\"/>" +
"<property xmlns=\"urn:uddi-org:api_v2\" name=\"operatorName\" value=\"jUDDI.org\"/>" +
"<property xmlns=\"urn:uddi-org:api_v2\" name=\"registryVersion\" value=\"0.9rc4\"/>" +
"<property xmlns=\"urn:uddi-org:api_v2\" name=\"uddiVersion\" value=\"2.0\"/>" +
"</registryInfo>";
try
{ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new ByteArrayInputStream(s.getBytes())); writeXmlFile(doc); SOAPMessage soapRes = null; MessageFactory msgFactory = MessageFactory.newInstance(); soapRes = msgFactory.createMessage(); soapRes.getSOAPBody().addDocument(doc); System.out.println("\n-----------------------------------------------------------------------"); writeXmlFile(soapRes.getSOAPBody()); }catch (Exception e)
{ System.out.println(e.getMessage()); }}
public static void writeXmlFile(Node node) {
try
catch (TransformerConfigurationException e) {
} catch (TransformerException e) {
}
}
produces this output (indents added for readability):
<?xml version="1.0" encoding="UTF-8"?>
<registryInfo xmlns="urn:uddi-org:api">
<property xmlns="urn:uddi-org:api_v2" name="operatorEmailAddress" value="admin@juddi.org"/>
<property xmlns="urn:uddi-org:api_v2" name="operatorName" value="jUDDI.org"/>
<property xmlns="urn:uddi-org:api_v2" name="registryVersion" value="0.9rc4"/>
<property xmlns="urn:uddi-org:api_v2" name="uddiVersion" value="2.0"/>
</registryInfo>
-----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:axis2ns1="">
<axis2ns3:registryInfo xmlns:axis2ns2="" xmlns:axis2ns3="">
<property name="operatorEmailAddress" value="admin@juddi.org"/>
<property name="operatorName" value="jUDDI.org"/>
<property name="registryVersion" value="0.9rc4"/>
<property name="uddiVersion" value="2.0"/>
</axis2ns3:registryInfo>
</soapenv:Body>
Where the namespaces are blank after adding the XML to the SOAPMessage's body.
This is using the simplest example I could make. In my actual project, where essentially the same code is being executed, I get something like this returned, which is the opposite problem...too many namespaces:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:axis2ns18="urn:uddi-org:api">
<axis2ns24:registryInfo xmlns:axis2ns24="urn:uddi-org:api" xmlns:axis2ns13="urn:uddi-org:api_v2" xmlns:axis2ns17="urn:uddi-org:api_v2" xmlns:axis2ns19="urn:uddi-org:api" xmlns:axis2ns5="urn:uddi-org:api_v2" xmlns:axis2ns9="urn:uddi-org:api_v2">
<axis2ns5:property xmlns:axis2ns20="urn:uddi-org:api_v2" name="operatorEmailAddress" value="admin@juddi.org" xmlns:axis2ns5="urn:uddi-org:api_v2"/>
<axis2ns9:property xmlns:axis2ns21="urn:uddi-org:api_v2" name="operatorName" value="jUDDI.org" xmlns:axis2ns9="urn:uddi-org:api_v2"/>
<axis2ns13:property xmlns:axis2ns22="urn:uddi-org:api_v2" name="registryVersion" value="0.9rc4" xmlns:axis2ns13="urn:uddi-org:api_v2"/>
<axis2ns17:property xmlns:axis2ns23="urn:uddi-org:api_v2" name="uddiVersion" value="2.0" xmlns:axis2ns17="urn:uddi-org:api_v2"/>
</axis2ns24:registryInfo>
</soapenv:Body>