users@jaxb.java.net

Re: XSD simplification for CRUD?

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Sat, 26 Feb 2011 07:55:25 +0100

You can define the elements

     <xs:element name="someDataElement">
     </xs:element>
     <xs:element name="anotherDataElement">
     </xs:element>

and the aggregations

  <xs:complexType name="event">
    <xs:all>
      <xs:element ref="app:someDataElement" minOccurs="1"/>
      <xs:element ref="app:anotherDataElement" minOccurs="1"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="eventUpdate">
    <xs:all>
      <xs:element name="primaryKey" type="app:eventPrimaryKey"
minOccurs="1"/>
      <xs:element ref="app:someDataElement" minOccurs="0"/>
      <xs:element ref="app:anotherDataElement" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

-W

On 25 February 2011 20:24, Colin Freas <colinfreas_at_gmail.com> wrote:

>
> 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
>