Java Mailing List Archive

Home » user.castor »

[castor-user] Unmarshalling sequence with optional elements



Replies: Find Java Web Hosting

Author LoginPost Reply


I'm struggling with a mapping/unmarshalling of a XML which contains a
sequence with an optional element.

Here is the XSD part for the list:

    <xs:element name="relations" maxOccurs="1" minOccurs="0"

 <xs:complexType name="relationsType">
     <xs:documentation xml:lang="en">Either a set of a lead project and a
lead-sourcing scope or a set of cosourced projects with an optional sourcing
   <xs:choice minOccurs="1" maxOccurs="1">
     <xs:sequence minOccurs="1" maxOccurs="1">
       <xs:element name="leadProject" type="projectType" minOccurs="1"
       <xs:element name="leadSs" maxOccurs="1" minOccurs="1" type="ssRefType"/>
     <xs:sequence maxOccurs="500" minOccurs="1">
       <xs:element name="coProject" maxOccurs="1" minOccurs="1"
         <xs:documentation xml:lang="en">CoProject (short for co-sourced
project) names and identifies a co-sourced project.</xs:documentation>
       <xs:element name="coSs" maxOccurs="1" minOccurs="0" type="ssRefType">

The element coSs is optional and may occur 0 or 1 times.
Here is a snippet of the corresponding XML:

    <coProject name="&gt;project &quot;full&quot; name&lt;"
short="project short name" id="PROJ_ID"/>
    <coSs number="9876-12" id="54987321"/>

    <coProject name="blubberbla" short="blubberbla short name"
    <coProject name="CoSourced01Vu" short="MVP 02 w/ VU"
    <coSs number="9999-99" id="12345678"/>

I want coProject and coSs be coupled together on the Java side in one object
in the list. The coupling is defined by the order of the elements. So the
first obj in the list would have PROJ_ID and 54987321; second only
blubber_bla without a coSs info and the third processed like the 1st one.
The thing with the lead choice is an additional case (then there are no
co-elements and exactly two lead elements).

The Java list element (which is actually a hibernate domain object) looks
like this:

public class VuRelation implements {

  private Long id; // internal id
  private SourcingScope sourcingScope; // ref to parent

  // set for lead-sourcing
  private String leadVuId;
  private String leadVuNr;

  private String leadProjectId;
  private String leadProjectShortName;
  private String leadProjectName;

  // set for co-sourcing
  private String coVuId;
  private String coVuNr;

  private String coProjectId;
  private String coProjectShortName;
  private String coProjectName;

... and linked in the main object like this:

public class SourcingScope implements {
  private Set<VuRelation> relations = new HashSet<VuRelation>();

How should the castor mapping look like for this case? How can I "tell"
castor to encapsulate certain elements on the same hierarchy xml level into
one object (combined with optional elements)?

Any help is appreciated!
Sent from the Castor - User mailing list archive at

To unsubscribe from this list, please visit:

©2008 - Jax Systems, LLC, U.S.A.