Pages

Wednesday, June 3, 2015

Generate Serializable classes from XSD schema

Below is the code snippet to generate the serializable classes from Xsd schema xml:
Part 1: this section is normal to xsd file.
1
2
3
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="http://www.apertio.com/webservice/TmoUsEIRSoap/v1"
    xmlns:typens="http://www.apertio.com/webservice/TmoUsEIRSoap/v1"
Part 2: Below section is the required attributes/values to generate the serializable classes for xsd.
4
5
6
7
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc"
    jaxb:version="1.0" >
Part 3:Below section is the required xml tags to generate the serializable classes for xsd.
8
9
10
11
12
13
14
<xsd:annotation>
   <xsd:appinfo>
      <jaxb:globalBindings generateIsSetMethod="false">
         <xjc:serializable uid="1"/>
      </jaxb:globalBindings>
   </xsd:appinfo>
</xsd:annotation>
Part 4: Finally this section is normal to xsd file which contains the xsd elements.
15
16
17
18
19
20
21
22
23
24
25
<xsd:element name="QueryReq">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element type="xsd:integer" minOccurs="1" maxOccurs="1" name="tranId" />
            <xsd:element type="xsd:integer" minOccurs="1" maxOccurs="1" name="reqId" />
            <xsd:element type="xsd:integer" minOccurs="0" maxOccurs="1" name="version" />
            <xsd:element type="xsd:string" minOccurs="0" maxOccurs="1" name="capability" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>

No comments:

Post a Comment