I have a set of CRUD request/response elements defined in XSD. A create
something like:
<xs:element name="CreateEventRequest">
<xs:complexType>
<xs:all>
<xs:element name="event" type="app:event"/>
</xs:all>
</xs:complexType>
</xs:element>
Then I have an update request like:
<xs:element name="UpdateEventRequest">
<xs:complexType>
<xs:all>
<xs:element name="event" type="app:eventUpdate"/>
</xs:all>
</xs:complexType>
</xs:element>
I define the event type:
<xs:complexType name="event">
<xs:all>
<xs:element name="someDataElement" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:element>
<xs:element name="anotherDataElement" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
..and the eventUpdate type:
<xs:complexType name="eventUpdate">
<xs:all>
<xs:element name="primaryKey" type="app:eventPrimaryKey"
minOccurs="1"/>
<xs:element name="someDataElement" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:element>
<xs:element name="anotherDataElement" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
(These are illustrative examples. My actual XSD is lengthier.)
Obviously, event and eventUpdate are very similar. but there are
differences: event creates a new event, and doesn't need the primary key,
because it's generated at object creation. Also, both data elements are
required in the create request. eventUpdate, however, does require a
primary key, and both data elements are optional: you can update either,
both, or, technically, neither.
So, I'm wondering if there's a common idiom or some XSD feature (I've looked
at *redefine*, and may use that) that would allow me to have some kind of
base type, where I can then specify which elements are required and which
are optional.
Or, is there some other XSD/JAXB/WS paradigm that simplifies the code needed
for a CRUD interface to a system?
Any thoughts appreciated.
-Colin