I have a JAXB object (ProductRequest) that represents an XML document for a webservice request. Assume it looks something like this:\[code\]<ProductRequest><getProducts/></ProductRequests>\[/code\]For the response, the JAXB object (ProductResponse) will represent an XML document as shown below:\[code\]<ProductResponse> <productId>1</productId> <productName>Oranges</productName> <productId>2</productId> <productName>Apples</productName></ProductResponse>\[/code\]Using Spring-WS, i can send the web service the request using two approachesUsing the JAXB object\[code\]ProductRequest productRequest = new productRequest();ProductResponse productResponse = (ProductResponse) webServiceTemplate .marshalSendAndReceive(productRequest);\[/code\]Using plain XML/DOM\[code\]DOMResult domresult = new DOMResult();webServiceTemplate.sendSourceAndReceiveToResult(source, domresult); //source represents the XML document as a DOMSource objectElement responseElement = (Element) domresult.getNode().getFirstChild();\[/code\]When i try both approaches, the results are different. The first approach using the JAXB object the result is\[code\]<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ProductResponse xmlns="http://mySchema"> <productId>1</productId> <productName>Oranges</productName> <productId>2</productId> <productName>Apples</productName></ProductResponse>\[/code\]The second approach using the XML Dom object the result is (Includes namespaces)\[code\]<?xml version="1.0" encoding="UTF-8"?> <ns2roductResponse xmlns:ns2="http://mySchema"> <ns2roductId>1</ns2roductId> <ns2roductName>Oranges</ns2roductName> <ns2roductId>2</ns2roductId> <ns2roductName>Apples</ns2roductName></ns2roductResponse>\[/code\]The header for the schema used for the response on the web service is declared as:\[code\]<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:z="http://mySchema" targetNamespace="http://mySchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> -- Schema elements</xs:schema>\[/code\]There are two differences in the response
- The first line on the response from JAXB request includes the entry standalone="yes">
- The elements on the JAXB version are not prefixed with the namespace
- Shouldn't the response with elements prefixed with the schema have used "z" (as defined in the schema) instead of ns2?