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. php 仿百度文库

    http://www.haosblog.com/?mod=article_read&id=386

  2. JavaScript获取HTML页面源代码

    来自:http://www.cnblogs.com/luckbird/archive/2008/02/01/1061048.html <a href="javascript:gets( ...

  3. hql注意事项一

    Space is not allowed after parameter prefix ':' [from EmPaperCatalogDef e where e.parentId =: pcdId]

  4. Javascript注意事项四【提高循环性能的策略】

    for(var i = item.length;i--){ process(item[i]); } 1.通过倒叙循环 2.最小化属性查询 3.尽量不要使用函数迭代(forEach)

  5. 学习和理解C#中的事件

    注:本文系学习笔记. 上一篇文章记录了我对C#中委托的理解.委托实际上是一种类型.可以将一个或多个方法绑定到委托上面,调用委托时,一次执行委托上面绑定的方法.本文要讲述的事件实际上和委托有很深的“感情 ...

  6. UITextView光标在中间的问题

    if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) { self.automatica ...

  7. Android develop tricks——整理自国外的一些Blog

    ViewDragHelper --视图拖动是一个比較复杂的问题.这个类能够帮助解决不少问题.假设你须要一个样例,DrawerLayout就是利用它实现扫滑.Flavient Laurent 还写了一些 ...

  8. cocos2dx 运动+旋转动画 CCSequence CCAnimation CCAnimate CCMoveTo CCCallFuncN

    cocos2dx 动画是个非常奇妙的东西~~. 这里看到的是一个物体,在运动的过程中会不断地翻转的过程. 两个动画一起来~~ 以下的代码中涉及到:CCAnimation(补间动画 )  CCAnima ...

  9. Nuget控制台 - 给你的快速添加缺少的包

    利用命令行安装包

  10. hdu 5461 Largest Point 暴力

    Largest Point Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...