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 for deciding between using an element or an attribute. (If you look for guidance, the schema describing the XML Schema language itself, making judicious use of both, is a good example.) JAXB, of course, has to be told when to make a field into an XML attribute.
The annotation for creating an XML attribute is XmlAttribute. Its elements correspond to what can be defined in an XML schema:
namedefines the namestring for the attribute, the default being the class field's name.namespacespecifies the XML target namespace to be used for the attribute's name.- A "true" value of
requiredis the same as using the XML Schema definition's attributeuse="required".
If you ask about some way for defining the equivalent for the XML Schema attribute default="value", then the simple answer is: "Do it yourself." Just write the getter so that it returns the default value if the field's value is null.
It's possible to annotate a static final field with XmlAttribute. This has the same effect as an XML Schema definition where the attribute element's attribute fixed is set to that value.
@XmlAttribute
final static int answer = 42;
JAXB - Annotations, Class Fields as Attributes: XmlAttribute的更多相关文章
- 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 ...
- JAXB - Annotations, The Annotation XmlElement
The basic annotation for a field that's intended to be an element is XmlElement. It permits you to d ...
- JAXB - Annotations, Annotation for Classes: XmlType
This annotation adds information that would be available from a schema type, but isn't implied by a ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- JAXB - Annotations, Type Mapping: XmlSchemaType
The annotation XmlSchemaType defines a mapping between an arbitrary Java type and a simple schema bu ...
- JAXB - Annotations, Annotations for Enums: XmlEnum, XmlEnumValue
An enum type is annotated with XmlEnum. It has an optional element value of type java.lang.Class whi ...
随机推荐
- 谈谈Nginx有哪些特点
1.热部署 我个人觉得这个很不错.在master管理进程与worker工作进程的分离设计,使的Nginx具有热部署的功能,那么在7×24小时不间断服务的前提下,升级Nginx的可执行文件 ...
- HW6.29
public class Solution { public static void main(String[] args) { int count = 0; int[] card = new int ...
- C++中实现从std::string类型到bool型的转换
利用输入字符串流:std::istringstream bool b; std::string s = "true"; std::istringstream(s) >> ...
- SQL 存储过程(学生,课程表,选修表)
SQL 存储过程(学生,课程表,选修表) 一.存储过程的分类 在SQL Server中存储过程分过两类: 1)系统存储过程("sp_"作为前缀) 2)用户自定义存储过程 二.创建和 ...
- Fox-H 函数
1.定义 2.特例 3.在分数阶微分方程中的应用 4.如何画图
- TabControl控件的美化
文件下载:http://files.cnblogs.com/zfanlong1314/TabControlEX.rar 本文转载:http://www.cnblogs.com/lmlblog/arch ...
- linux内核编译步骤
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- cocos2d-x Touch
转自:http://codingnow.cn/cocos2d-x/783.html 游戏跟视频最大的区别就是互动,玩家可以操控游戏中的角色,现在的移动设备几乎人手一台,基本上全部都是基于触屏操作的,今 ...
- 字母A-Z写法
#大写的a-z,ASCII编码 65..90|%{[char]$_} #小写的A-Z 97..122|%{[char]$_} 方法二: ([char[]](97..122) -as [ ...
- 【转】与BT下载相关的概念
1. DHT DHT全称叫分布式哈希表(Distributed Hash Table),是一种分布式存储方法.在不需要服务器的情况下,每个客户端负责一个小范围的路由,并负责存储一小部分数据,从而实现整 ...