Spring web service returning different results when using JAXB or XML DOM objects

Doc1952

New Member
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"?> <ns2:ProductResponse xmlns:ns2="http://mySchema"> <ns2:productId>1</ns2:productId> <ns2:productName>Oranges</ns2:productName> <ns2:productId>2</ns2:productId> <ns2:productName>Apples</ns2:productName></ns2:ProductResponse>\[/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?
I don't understand what could be causing this difference given that they are both calling the same web service which generates the response based on the same schema. Any ideas? The XML content is the same but the difference in the format of the XML is giving me problems as i cant use String.equals() to compare the two.
 
Back
Top