@Retention(value=RUNTIME) @Target(value={字段,METHOD}) public @interface XmlAnyElement
当将xml内容解组到JAXB注释类的实例中时,此注释用作“全部”属性。 它通常会注释多值JavaBean属性,但它可以发生在单值JavaBean属性上。 在解组时,与该类上其他JavaBean属性的静态@XmlElement或@XmlElementRef注释不匹配的每个xml元素都添加到此“catch-all”属性中。
  @XmlAnyElement
 public Element[] others;
 // Collection of Element or JAXB elements.
 @XmlAnyElement(lax="true")
 public Object[] others;
 @XmlAnyElement
 private List<Element> nodes;
 @XmlAnyElement
 private Element node;  
        此注释是互斥XmlElement , XmlAttribute , XmlValue , XmlElements , XmlID和XmlIDREF 。 
 一个类中只能有一个XmlAnyElement注释的JavaBean属性及其超类。 
 该注释可以与XmlJavaTypeAdapter一起使用,以便用户可以将自己的数据结构映射到DOM,而DOM又可以组成XML。 
 这个注释可以和XmlMixed一起使用: 
  // List of java.lang.String or DOM nodes.
 @XmlAnyElement @XmlMixed
 List<Object> others;  
         <xs:complexType name="foo">
   <xs:sequence>
     <xs:element name="a" type="xs:int" />
     <xs:element name="b" type="xs:int" />
     <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
   </xs:sequence>
 </xs:complexType>  
         class Foo {
   int a;
   int b;
   @XmlAnyElement
   List<Element> any;
 }  
       它可以解散实例 
         <foo xmlns:e="extra">
   <a>1
   <e:other />  // this will be bound to DOM, because unmarshalling is orderless
   <b>3
   <e:other />
   <c>5     // this will be bound to DOM, because the annotation doesn't remember namespaces.
 </foo>  
       以下模式将生成以下Java类: 
         <xs:complexType name="bar">
   <xs:complexContent>
   <xs:extension base="foo">
     <xs:sequence>
       <xs:element name="c" type="xs:int" />
       <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
     </xs:sequence>
   </xs:extension>
 </xs:complexType>  
         class Bar extends Foo {
   int c;
   // Foo.getAny() also represents wildcard content for type definition bar.
 }  
       它可以解散实例 
         <bar xmlns:e="extra">
   <a>1
   <e:other />  // this will be bound to DOM, because unmarshalling is orderless
   <b>3
   <e:other />
   <c>5     // this now goes to Bar.c
   <e:other />  // this will go to Foo.any
 </bar>  
       XmlAnyElement与XmlElementRef  XmlAnyElement注释可以与XmlElementRef s一起使用,以指定可以参与内容树的其他元素。 
以下模式将生成以下Java类:
  <xs:complexType name="foo">
   <xs:choice maxOccurs="unbounded" minOccurs="0">
     <xs:element name="a" type="xs:int" />
     <xs:element name="b" type="xs:int" />
     <xs:any namespace="##other" processContents="lax" />
   </xs:choice>
 </xs:complexType>  
         class Foo {
   @XmlAnyElement(lax="true")
   @XmlElementRefs({
     @XmlElementRef(name="a", type="JAXBElement.class")
     @XmlElementRef(name="b", type="JAXBElement.class")
   })
   List<Object> others;
 }
 @XmlRegistry
 class ObjectFactory {
   ...
   @XmlElementDecl(name = "a", namespace = "", scope = Foo.class)
   JAXBElement<Integer> createFooA( Integer i ) { ... }
   @XmlElementDecl(name = "b", namespace = "", scope = Foo.class)
   JAXBElement<Integer> createFooB( Integer i ) { ... }  
       它可以解散实例 
         <foo xmlns:e="extra">
   <a>1     // this will unmarshal to a JAXBElement instance whose value is 1.
   <e:other />  // this will unmarshal to a DOM Element.
   <b>3     // this will unmarshal to a JAXBElement instance whose value is 1.
 </foo>  
         @XmlRootElement
 class Foo {
   @XmlAnyElement(lax=true)
   public Object[] others;
 }  
       那么以下文档将如下解密: 
         <foo>
   <unknown />
   <foo />
 </foo>
 Foo foo = unmarshal();
 // 1 for 'unknown', another for 'foo'
 assert foo.others.length==2;
 // 'unknown' unmarshals to a DOM element
 assert foo.others[0] instanceof Element;
 // because of lax=true, the 'foo' element eagerly
 // unmarshals to a Foo object.
 assert foo.others[1] instanceof Foo;  
      | Modifier and Type | Optional Element and Description | 
|---|---|
| boolean | lax 
             当它看到当前 JAXBContext已知的元素时,控制解组器行为。 | 
| 类<? extends DomHandler> | value 
             指定 DomHandler,它负责将XML从/转换为类似DOM的数据结构。 | 
public abstract boolean lax
JAXBContext已知的元素时,控制解组器行为。 
           如果为false,则与DOM属性匹配的所有元素将被取消组织到DOM,该属性将仅包含DOM元素。
 如果为true,当一个元素匹配标有XmlAnyElement的属性是已知的JAXBContext (例如,有一个类与XmlRootElement具有相同的标签名称,或有XmlElementDecl具有相同的标签名称),解组器将热切地解散这个元素到JAXB对象,而不是将其解组到DOM。 另外,如果元素未知但是具有已知的xsi:type,则unmarshaller会将元素强制解组为JAXBElement ,其中未知元素名称和JAXBElement值设置为已知xsi:type的JAXB映射的实例。 
结果,在解组之后,财产可能变得异质性; 它可以同时拥有DOM节点和一些JAXB对象。
这可以用来模拟W3C XML Schema的“宽松”通配符语义。
public abstract 类<? extends DomHandler> value
DomHandler ,它负责将XML从/转换为类似DOM的数据结构。 
           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.