Spec-Zone.ru › OpenJDK 8

Тип аннотации XmlMixed


@Retention(value=RUNTIME)
 @Target(value={FIELD,METHOD})
public @interface XmlMixed

Аннотирует многозначное свойство JavaBean для поддержки смешанного содержимого.

Использование ограничено следующими условиями:

  • может использоваться с @XmlElementRef, @XmlElementRefs или @XmlAnyElement

Следующее может быть вставлено в многозначное свойство, аннотированное @XmlMixed

  • Элементы текстовой информации XML добавляются как значения java.lang.String.
  • Элементы информации дочерних элементов добавляются как экземпляры JAXBElement или экземпляры с классом, аннотированным @XmlRootElement.
  • Неизвестное содержимое, которое не привязано к классу, сопоставленному JAXB, вставляется как Element. (Предполагается, что свойство аннотировано с помощью @XmlAnyElement)
Ниже приведен пример привязки и создания смешанного содержимого.
<!-- schema fragment having  mixed content -->
  <xs:complexType name="letterBody" mixed="true">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="quantity" type="xs:positiveInteger"/>
      <xs:element name="productName" type="xs:string"/>
      <!-- etc. -->
    </xs:sequence>
  </xs:complexType>
  <xs:element name="letterBody" type="letterBody"/>

 // Schema-derived Java code:
 // (Only annotations relevant to mixed content are shown below,
 //  others are ommitted.)
 import java.math.BigInteger;
 public class ObjectFactory {
      // element instance factories
      JAXBElement<LetterBody> createLetterBody(LetterBody value);
      JAXBElement<String>     createLetterBodyName(String value);
      JAXBElement<BigInteger> createLetterBodyQuantity(BigInteger value);
      JAXBElement<String>     createLetterBodyProductName(String value);
      // type instance factory
      LetterBody> createLetterBody();
 }
public class LetterBody {
      // Mixed content can contain instances of Element classes
      // Name, Quantity and ProductName. Text data is represented as
      // java.util.String for text.
      @XmlMixed
      @XmlElementRefs({
              @XmlElementRef(name="productName", type=JAXBElement.class),
              @XmlElementRef(name="quantity", type=JAXBElement.class),
              @XmlElementRef(name="name", type=JAXBElement.class)})
      List getContent(){...}
 }
Следующий XML-документ с смешанным содержимым
<letterBody>
 Dear Mr.<name>Robert Smith</name>
 Your order of <quantity>1</quantity> <productName>Baby
 Monitor</productName> shipped from our warehouse. ....
 </letterBody>
может быть создан с помощью следующих вызовов API JAXB.
LetterBody lb = ObjectFactory.createLetterBody();
 JAXBElement<LetterBody> lbe = ObjectFactory.createLetterBody(lb);
 List gcl = lb.getContent();  //add mixed content to general content property.
 gcl.add("Dear Mr.");  // add text information item as a String.

 // add child element information item
 gcl.add(ObjectFactory.createLetterBodyName("Robert Smith"));
 gcl.add("Your order of "); // add text information item as a String

 // add children element information items
 gcl.add(ObjectFactory.
                      createLetterBodyQuantity(new BigInteger("1")));
 gcl.add(ObjectFactory.createLetterBodyProductName("Baby Monitor"));
 gcl.add("shipped from our warehouse");  // add text information item

Дополнительную общую информацию см. в разделе «Спецификация пакета» в документации пакета javax.xml.bind.

С:
JAXB2.0

© 1993, 2020, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API