Xsd simpleXML xs:choice元素

Xsd simpleXML xs:choice元素,xsd,simplexml,element,choice,annotate,Xsd,Simplexml,Element,Choice,Annotate,我有以下资料: <xs:complexType name="AnswerType"> <xs:choice minOccurs="1" maxOccurs="1"> <xs:element name="Checklist" type="ChecklistType" /> <xs:element name="OptionList" type="OptionListType" /> <xs:

我有以下资料:

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

当然还有更好的办法。一个必须是required=true,但是如何呢?

我在教程中找不到这个问题的答案,但我翻到了示例,找到了第二个示例来解决这个问题。在javadocs中查找该类。例如


我在教程中找不到这个问题的答案,但我翻到了例子,找到了第二个例子来解决这个问题。在javadocs中查找该类。例如

@Element(name = "Checklist", required=false)
protected ChecklistType checklist;
@Element(name = "OptionList", required=false)
protected OptionListType optionList;
@Element(name = "Measurement", required=false)
protected MeasureType measurement;
@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;
}