首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >simpleXML xs:choice元素

simpleXML xs:choice元素
EN

Stack Overflow用户
提问于 2012-07-11 03:36:17
回答 1查看 384关注 0票数 1

我有以下几点:

代码语言:javascript
复制
<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

代码语言:javascript
复制
@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,但是如何使用呢?

EN

回答 1

Stack Overflow用户

发布于 2012-12-05 00:08:06

我在教程中找不到这个问题的答案,但我翻到了例子,找到了第二个例子来解决这个问题。在javadoc中查找ElementUnion类。示例是here

代码语言:javascript
复制
@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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11420608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档