0

I have a xml string which is a response from third party server.

   <?xml version="1.0" encoding="utf-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
     <SOAP-ENV:Body>
       <GetRateQuoteResponse>  
          <GetRateQuoteResult>       
          </GetRateQuoteResult>   
       </GetRateQuoteResponse> 
    </SOAP-ENV:Body></SOAP-ENV:Envelope>

I want to parse it in JAX-WS. So i converted this String to xsd file using this web site

The web site gave me the xsd as follows.

<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="SOAP-ENV:Envelope">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="SOAP-ENV:Body">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="GetRateQuoteResponse">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="GetRateQuoteResult" type="xsd:string" />
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

I now generate JaxB classes from this xsd, it tries to create class named SOAP-ENV:Envelope and SOAP-ENV:Body which is invalid name for a class and it fails to do so.

Also even if i modify xsd to Envelope and Body the Unmarshalling fails.

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"). Expected elements are <{}SOAP-ENV:Envelope>

Please guide.

Shashank Degloorkar
  • 3,151
  • 4
  • 32
  • 50
  • Add the namespace definition `xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"` to the XML schema element `xsd:schema`. Normally the envelope is handled by the Web service software. – laune Dec 29 '14 at 12:59

1 Answers1

0

The XSD should not contain any SOAP elements; only the WSDL does. The XSD by definition is or data only. The transport protocol information (SOAP) should not be in the data definition as XSDs have applications outside of SOAP.

Omit the SOAP schema elements from the entry you pass to the XSD generato. By including that stuff in there, you're indicating to the generator that those elements will be part of your JAXB-generated classes (which shouldn't be the case). What you should feed the generator is the excerpt below, which would rightly generate the GetRateQuoteResponse-containing schema

     <GetRateQuoteResponse>  
         <GetRateQuoteResult>       
         </GetRateQuoteResult>   
     </GetRateQuoteResponse> 

The result:

     <?xml version="1.0" encoding="utf-16"?>
         <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:element name="GetRateQuoteResponse">
                 <xsd:complexType>
                      <xsd:sequence>
                         <xsd:element name="GetRateQuoteResult" type="xsd:string" />
                      </xsd:sequence>
                 </xsd:complexType>
            </xsd:element>
         </xsd:schema>
kolossus
  • 20,559
  • 3
  • 52
  • 104