1

I have the following:

<xs:complexType name="AnswerType">
    <xs:choice minOccurs="1" maxOccurs="1">
        <xs:element name="Checklist" type="ChecklistType" />
        <xs:element name="OptionList" type="OptionListType" />
        <xs:element name="Measurement" type="MeasureType" />
    </xs:choice>
</xs:complexType> 

How to I annotate the choice XSD element using SimpleXML? Currently I have to set them all to required=false

@Element(name = "Checklist", required=false)
protected ChecklistType checklist;
@Element(name = "OptionList", required=false)
protected OptionListType optionList;
@Element(name = "Measurement", required=false)
protected MeasureType measurement;

Surely there's a better way. One has to the required=true but how?

dan1st
  • 12,568
  • 8
  • 34
  • 67
Bugz
  • 118
  • 1
  • 9

1 Answers1

1

i couldn't find the answer to this in the Tutorial, but i flipped over to the examples and found the second example to solve exactly this. look up the ElementUnion class in the javadocs. the example is here

@Root
public class Example {

   @ElementUnion({
      @Element(name="text", type=String.class),
      @Element(name="int", type=Integer.class),
      @Element(name="double", type=Double.class)
   })
   private Object value;
}
moonlightcheese
  • 10,664
  • 9
  • 49
  • 75