zoukankan      html  css  js  c++  java
  • JAXB

    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:

    • name defines the namestring for the attribute, the default being the class field's name.
    • namespace specifies the XML target namespace to be used for the attribute's name.
    • A "true" value of required is the same as using the XML Schema definition's attribute use="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;
  • 相关阅读:
    孙权劝学
    劝学
    为学
    字符串的全排列
    剑指offer面试题3二维数组中的查找
    如何正确安装软件
    写给自己的话
    Linux常用命令
    第三届华为杯
    D^3ctf两道 pwn
  • 原文地址:https://www.cnblogs.com/huey/p/5512274.html
Copyright © 2011-2022 走看看