2

By the use of the command line tool 'xjc' for example, it is possible to create Java classes from an existing XML Schema.

I've tried that with a simple XML Schema before:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

 <xs:element name="employee" type="employee"/>

 <xs:complexType name="employee">
  <xs:sequence>
    <xs:element name="name" type="xs:string" minOccurs="0"/>
    <xs:element name="salary" type="xs:double"/>
    <xs:element name="designation" type="xs:string" minOccurs="0"/>
    <xs:element name="address" type="address" minOccurs="0"/>
  </xs:sequence>
  <xs:attribute name="id" type="xs:int" use="required"/>
 </xs:complexType>

 <xs:complexType name="address">
  <xs:sequence>
    <xs:element name="city" type="xs:string" minOccurs="0"/>
    <xs:element name="line1" type="xs:string" minOccurs="0"/>
    <xs:element name="line2" type="xs:string" minOccurs="0"/>
    <xs:element name="state" type="xs:string" minOccurs="0"/>
    <xs:element name="zipcode" type="xs:long"/>
  </xs:sequence>
 </xs:complexType> 
</xs:schema>

But when I add a definition which has some restrictions, the restrictions will be just ignored. For example:

<xs:element name="Temperature" type="myTemperature"/>
<xs:simpleType name="myTemperature">
 <xs:restriction base="xs:double">
  <xs:minExclusive value="-273.15"/>
 </xs:restriction>
</xs:simpleType>

or

<xs:element name="age">
 <xs:simpleType>
  <xs:restriction base="xs:integer">
   <xs:minInclusive value="0"/>
   <xs:maxInclusive value="100"/>
  </xs:restriction>
 </xs:simpleType>
</xs:element> 

All the restrictions like minInclusive, maxInclusive, maxLength, totalDigits, etc. will be ignored. Is there a way to include this restrictions in the creation of the Java classes from the XML Schema?

FredFloete
  • 627
  • 2
  • 13
  • 33
  • 1
    Duplicate of http://stackoverflow.com/questions/13775465/does-jaxb-support-xsdrestriction?? – lreeder Jul 11 '13 at 14:29
  • 2
    @lreeder Definitely not duplicate. The linked question wants to do things the other way around (Java -> XSD), this one wants XSD -> Java. – vbence Feb 27 '14 at 09:29
  • @vbence, I'm not sure why you are saying this. The linked question provides a schema, and the java code that it *wants to generate* from the schema, so it is also XSD->Java. Both questions want to generate restrictions in java from restrictions defined in the schema. – lreeder Mar 02 '14 at 18:15
  • It's not easy to parse, but OP in the linked question says "I want it to get converted **to** Java code", not "**from** Java code". – lreeder Mar 02 '14 at 18:25
  • @lreeder On second read, you're absolutely right. – vbence Mar 02 '14 at 21:06

0 Answers0