Spec-Zone .ru
спецификации, руководства, описания, API


javax.xml.bind.annotation
Тип аннотации XmlMixed


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

Аннотируйте JavaBean многозначное свойство, чтобы поддерживать смешанный контент.

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

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

Ниже пример привязки и создания смешанного контента.

  <!-- 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&gt; 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(&quot;Dear Mr.&quot;);  // add text information item as a String.
 
 // add child element information item
 gcl.add(ObjectFactory.createLetterBodyName(&quot;Robert Smith&quot;));
 gcl.add(&quot;Your order of &quot;); // add text information item as a String
 
 // add children element information items
 gcl.add(ObjectFactory.
                        createLetterBodyQuantity(new BigInteger(&quot;1&quot;)));
 gcl.add(ObjectFactory.createLetterBodyProductName(&quot;Baby Monitor&quot;));
 gcl.add(&quot;shipped from our warehouse&quot;);  // add text information item
 

См. "Спецификацию Пакета" в javax.xml.bind.package javadoc для дополнительной общей информации.

С тех пор:
JAXB2.0
Автор:
Kohsuke Кавагути



Представьте ошибку или функцию

Авторское право © 2009-2011, Oracle Corporation и/или его филиалы. Все права защищены. Использование подвергается срокам действия лицензии.

Сгенерированный на 10-February-2011 12:41

free hit counter