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. leetcode—Same Tree

    1.题目描述 Given two binary trees, write a function to check if they are equal or not.   Two binary tree ...

  2. 浅析Netty的异步事件驱动(一)

    本篇文章着重于浅析一下Netty的事件处理流程,Netty版本为netty-3.6.6.Final. Netty定义了非常丰富的事件类型,代表了网络交互的各个阶段.并且当各个阶段发生时,触发相应的事件 ...

  3. 检索表中所有列的名称、DB中的用户表

    一.检索某个表中所有列的名称 SELECT name FROM syscolumns WHERE ID = OBJECT_ID('Departments') syscolumns (sys.sysco ...

  4. 【noip2012】疫情控制

    题意: 给出一颗n个节点有边权的树 和m个军队所在的位置 军队从某节点移动到相邻节点要花费边长度的时间 求最少要多少时间使得根节点(编号为1)到每个叶子的路径上最少有一支军队(根节点不能有军队) 题解 ...

  5. linux下ssh使用rsa验证登陆MACOX

    由于项目的需求,我这边ubuntu下常常需要SSH访问另外一台MACOS. 每次输入密码有点烦,就想到RSA公钥和密钥验证的方法. 像所有教程上讲的一样,本机执行 gong@hzsx:~$ ssh-k ...

  6. 问题-File not "controls.res"(XE2+Win7虚拟机)

    问题现象:我在Win7的虚拟机中安装XE2,前提是原来的系统上有D2007,安装后,新建个工程,F9报"File not controls.res".百思不得其解. 问题原因:因为 ...

  7. 关于UIImage类的对象两种初始化方法的区别

    1.imageNamed: UIImage *image = [UIImage imageNamed:"]; UIImage的类方法 第一次读取图片的时候,先把这个图片放到缓存中,下次再使用 ...

  8. support-v4不能查看源码

    在Android实际开发过程中往往会遇到使用v4,v7或v13兼容包中的一些类如ViewPager,Fargment等,但却无法关联源码 具体步骤: 1 右击Android项目中libs文件夹下的an ...

  9. ECSHOP在线手册之模板结构说明 (适用版本v2.7.3)

    名称 类型 备注(作用或意义) 文件(目录)名可否更改 images 目录 存放模板图片目录 不可更改 library 目录 存放模板库文件目录 不可更改 screenshot.png 图片 用于“后 ...

  10. cocos2d-x 技能冷却特效

    转自:http://blog.csdn.net/qiurisuixiang/article/details/8779540 1 在CSDN上看到某同学实现的Dota技能冷却效果,自己平时也玩Dota, ...