我有以下几点:
<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> 如何使用SimpleXML注释choice XSD元素?目前,我必须将它们都设置为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;当然还有更好的方法。一个人必须使用required=true,但是如何使用呢?
发布于 2012-12-05 00:08:06
我在教程中找不到这个问题的答案,但我翻到了例子,找到了第二个例子来解决这个问题。在javadoc中查找ElementUnion类。示例是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;
}https://stackoverflow.com/questions/11420608
复制相似问题