@Retention(value=RUNTIME) @Target(value={字段,METHOD}) public @interface XmlElements
多个@ XmlElement
注释的容器。 程序元素不允许使用相同类型的多个注释。 因此,此注释作为多个@XmlElements的容器注释,如下所示:
@XmlElements({ @XmlElement(...),@XmlElement(...) })
@XmlElements注解可以与以下程序元素一起使用:
用法
用法受以下限制:
XmlIDREF
,@ XmlElementWrapper
。 有关其他常见信息,请参阅javax.xml.bind.package javadoc中的“Package Specification”。
示例1:映射到元素列表
// Mapped code fragment
public class Foo {
@XmlElements(
@XmlElement(name="A", type=Integer.class),
@XmlElement(name="B", type=Float.class)
}
public List items;
}
<!-- XML Representation for a List of {1,2.5}
XML output is not wrapped using another element -->
...
<A> 1 </A>
<B> 2.5 </B>
...
<!-- XML Schema fragment -->
<xs:complexType name="Foo">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="A" type="xs:int"/>
<xs:element name="B" type="xs:float"/>
<xs:choice>
</xs:sequence>
</xs:complexType>
示例2:映射到包含另一个元素的元素列表
// Mapped code fragment
public class Foo {
@XmlElementWrapper(name="bar")
@XmlElements(
@XmlElement(name="A", type=Integer.class),
@XmlElement(name="B", type=Float.class)
}
public List items;
}
<!-- XML Schema fragment -->
<xs:complexType name="Foo">
<xs:sequence>
<xs:element name="bar">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="A" type="xs:int"/>
<xs:element name="B" type="xs:float"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
示例3:使用适配器根据类型更改元素名称。
class Foo {
@XmlJavaTypeAdapter(QtoPAdapter.class)
@XmlElements({
@XmlElement(name="A",type=PX.class),
@XmlElement(name="B",type=PY.class)
})
Q bar;
}
@XmlType abstract class P {...}
@XmlType(name="PX") class PX extends P {...}
@XmlType(name="PY") class PY extends P {...}
<!-- XML Schema fragment -->
<xs:complexType name="Foo">
<xs:sequence>
<xs:element name="bar">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="A" type="PX"/>
<xs:element name="B" type="PY"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
XmlElement
, XmlElementRef
, XmlElementRefs
, XmlJavaTypeAdapter
Modifier and Type | Required Element and Description |
---|---|
XmlElement[] |
value
@ XmlElement 注解的集合
|
public abstract XmlElement[] value
XmlElement
注释
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.