The basic annotation for a field that's intended to be an element is XmlElement. It permits you to define the XML element name, the namespace, whether it is optional or nillable, a default value and the Java class. Here are two annotated fields, and below is the corresponding schema snippet.

@XmlElement(name = "Preamble", required = true)
protected PreambleType preamble;
@XmlElement(name = "Workplace", required = true)
protected List<SysWorkplaceType> workplace;
<xsd:sequence>
<xsd:element name="Preamble" type="com:PreambleType"/>
<xsd:element name="Workplace" type="SysWorkplaceType" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>

If a field has some collection type, more than one @XmlElement may have to be associated with this field. This requires that these annotations are assembled in a XmlElements (not the plural "s") annotation that merely acts as a container. In the class definition below, the field entryOrChoiceOrCascade is a collection composed from objects of three different classes.

@XmlType(name = "MenuType")
public class MenuType extends ItemType { @XmlElements({
@XmlElement(name = "Item", type = ItemType.class),
@XmlElement(name = "CheckBox", type = CheckBoxType.class),
@XmlElement(name = "Menu", type = MenuType.class)
})
protected List entryList;
}

As a bonus you may avoid the complicated name for the list element that JAXB concocts from the first three possibles.

JAXB - Annotations, The Annotation XmlElement的更多相关文章

  1. ssm裤架搭建异常: Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' ...

  2. JAXB - Annotations, Annotation for Classes: XmlType

    This annotation adds information that would be available from a schema type, but isn't implied by a ...

  3. JAXB - Annotations, Controlling Element Selection: XmlAccessorType, XmlTransient

    If JAXB binds a class to XML, then, by default, all public members will be bound, i.e., public gette ...

  4. JAXB - Annotations, Top-level Elements: XmlRootElement

    A class that describes an XML element that is to be a top-level element, i.e., one that can function ...

  5. JAXB - Annotations, Type Adapters: XmlJavaTypeAdapter

    For some Java container types JAXB has no built-in mapping to an XML structure. Also, you may want t ...

  6. JAXB - Annotations, Type Mapping: XmlSchemaType

    The annotation XmlSchemaType defines a mapping between an arbitrary Java type and a simple schema bu ...

  7. JAXB - Annotations, Annotations for the Schema: XmlSchema

    This annotation can only be used with a package. It defines parameters that are derived from the xsd ...

  8. JAXB - Annotations, Class Fields as Attributes: XmlAttribute

    Provided that XML lets you represent a data item as a single value, there is no cut-and-dried rule f ...

  9. JAXB - Annotations, The Object Factory: XmlRegistry, XmlElementDecl

    To be able to create objects from XML elements, the unmarshaller must have an object factory with me ...

随机推荐

  1. flappy pig小游戏源码分析(3)——解剖util

    这一节我们继续高歌猛进,如果对源码中有无论无何都理解不通的问题,欢迎和我交流,让我也学习一下,我的qq是372402487. 还是按照惯例看看我们的目录结构. 我们在前两节中已经分析了game.js, ...

  2. 题解西电OJ (Problem 1004 -亚特兰提斯)--最小生成树

    Description 为了找寻沉睡的亚特兰提斯大陆,wm来到了大西洋上进行探险,找了半个月仍一无所获.然而在一次突袭而来的暴风雨后,wm的船莫名地驶入了一片未知的区域,发现了一个地图上未标记的岛屿, ...

  3. 【HBase学习】Apache HBase项目简介

    原创声明:转载请注明作者和原始链接 http://www.cnblogs.com/zhangningbo/p/4068957.html       英文原版:http://hbase.apache.o ...

  4. CM 部署bigdata测试环境群集机器报错

    CM repo库info;

  5. 大公司最喜欢问的Java集合类面试题

    看了一些所谓大公司的JAVA面试问题,发现对于JAVA集合类的使用都比较看重似的,而自己在这方面还真的是所真甚少,抽空也学习学习吧. java.util包中包含了一系列重要的集合类,而对于集合类,主要 ...

  6. notepad 如何同时选中同一列的数据 Alt

    有时会经常遇到这种情况, 我们要选中数据中的某一列,这个在记事本中是实现不了的,不过我们可以用更高级一点的编辑器. 使用notepad可以帮助我们解决这个问题哦! 操作方法就是 按下ALT键 然后再去 ...

  7. [Objective-c 基础 - 2.6] @property和@synthesize

    Xcode编译器的特性,自动生成getter和setter   A.@property 自动生成某个成员变量的getter和setter的声明 变量的命名要求:以下划线开头 Student.h @in ...

  8. js主要知识轮廓笔记

    一.js中的基础类型和引用类型: 基础类型:1.Number2.String3.Boolean4.Undefined5.Null 引用类型(内置对象):1.Object类型2.Array类型3.Dat ...

  9. RocketMQ入门(2)最佳实践

    转自:http://www.changeself.net/archives/rocketmq入门(2)最佳实践.html RocketMQ入门(2)最佳实践 一.服务端安装部署 我是在虚拟机中的Cen ...

  10. 写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如:  List list = new ArrayList();  list.add(“Hello”);  list.add(“World”);  list.add(“Learn”); //此时list 为Hello World Learn  reverseList

    package homework004; import java.util.ArrayList; import java.util.List; public class Daoxu { public ...