54 * <li>Unknown content that is not be bound to a JAXB mapped class is inserted |
54 * <li>Unknown content that is not be bound to a JAXB mapped class is inserted |
55 * as {@link Element}. (Assumes property annotated with @XmlAnyElement)</li> |
55 * as {@link Element}. (Assumes property annotated with @XmlAnyElement)</li> |
56 * </ul> |
56 * </ul> |
57 * |
57 * |
58 * Below is an example of binding and creation of mixed content. |
58 * Below is an example of binding and creation of mixed content. |
59 * <pre> |
59 * <pre>{@code |
60 * <!-- schema fragment having mixed content --> |
60 * |
61 * <xs:complexType name="letterBody" mixed="true"> |
61 * <!-- schema fragment having mixed content --> |
62 * <xs:sequence> |
62 * <xs:complexType name="letterBody" mixed="true"> |
63 * <xs:element name="name" type="xs:string"/> |
63 * <xs:sequence> |
64 * <xs:element name="quantity" type="xs:positiveInteger"/> |
64 * <xs:element name="name" type="xs:string"/> |
65 * <xs:element name="productName" type="xs:string"/> |
65 * <xs:element name="quantity" type="xs:positiveInteger"/> |
66 * <!-- etc. --> |
66 * <xs:element name="productName" type="xs:string"/> |
67 * </xs:sequence> |
67 * <!-- etc. --> |
68 * </xs:complexType> |
68 * </xs:sequence> |
69 * <xs:element name="letterBody" type="letterBody"/> |
69 * </xs:complexType> |
|
70 * <xs:element name="letterBody" type="letterBody"/> |
70 * |
71 * |
71 * // Schema-derived Java code: |
72 * // Schema-derived Java code: |
72 * // (Only annotations relevant to mixed content are shown below, |
73 * // (Only annotations relevant to mixed content are shown below, |
73 * // others are ommitted.) |
74 * // others are omitted.) |
74 * import java.math.BigInteger; |
75 * import java.math.BigInteger; |
75 * public class ObjectFactory { |
76 * public class ObjectFactory { |
76 * // element instance factories |
77 * // element instance factories |
77 * JAXBElement<LetterBody> createLetterBody(LetterBody value); |
78 * JAXBElement<LetterBody> createLetterBody(LetterBody value); |
78 * JAXBElement<String> createLetterBodyName(String value); |
79 * JAXBElement<String> createLetterBodyName(String value); |
79 * JAXBElement<BigInteger> createLetterBodyQuantity(BigInteger value); |
80 * JAXBElement<BigInteger> createLetterBodyQuantity(BigInteger value); |
80 * JAXBElement<String> createLetterBodyProductName(String value); |
81 * JAXBElement<String> createLetterBodyProductName(String value); |
81 * // type instance factory |
82 * // type instance factory |
82 * LetterBody createLetterBody(); |
83 * LetterBody createLetterBody(); |
83 * } |
84 * } |
84 * </pre> |
85 * }</pre> |
85 * <pre> |
86 * <pre> |
86 * public class LetterBody { |
87 * public class LetterBody { |
87 * // Mixed content can contain instances of Element classes |
88 * // Mixed content can contain instances of Element classes |
88 * // Name, Quantity and ProductName. Text data is represented as |
89 * // Name, Quantity and ProductName. Text data is represented as |
89 * // java.util.String for text. |
90 * // java.util.String for text. |
94 * @XmlElementRef(name="name", type=JAXBElement.class)}) |
95 * @XmlElementRef(name="name", type=JAXBElement.class)}) |
95 * List getContent(){...} |
96 * List getContent(){...} |
96 * } |
97 * } |
97 * </pre> |
98 * </pre> |
98 * The following is an XML instance document with mixed content |
99 * The following is an XML instance document with mixed content |
99 * <pre> |
100 * <pre>{@code |
100 * <letterBody> |
101 * <letterBody> |
101 * Dear Mr.<name>Robert Smith</name> |
102 * Dear Mr.<name>Robert Smith</name> |
102 * Your order of <quantity>1</quantity> <productName>Baby |
103 * Your order of <quantity>1</quantity> <productName>Baby |
103 * Monitor</productName> shipped from our warehouse. .... |
104 * Monitor</productName> shipped from our warehouse. .... |
104 * </letterBody> |
105 * </letterBody> |
105 * </pre> |
106 * }</pre> |
106 * that can be constructed using following JAXB API calls. |
107 * that can be constructed using following JAXB API calls. |
107 * <pre> |
108 * <pre>{@code |
108 * LetterBody lb = ObjectFactory.createLetterBody(); |
109 * LetterBody lb = ObjectFactory.createLetterBody(); |
109 * JAXBElement<LetterBody> lbe = ObjectFactory.createLetterBody(lb); |
110 * JAXBElement<LetterBody> lbe = ObjectFactory.createLetterBody(lb); |
110 * List gcl = lb.getContent(); //add mixed content to general content property. |
111 * List gcl = lb.getContent(); //add mixed content to general content property. |
111 * gcl.add("Dear Mr."); // add text information item as a String. |
112 * gcl.add("Dear Mr."); // add text information item as a String. |
112 * |
113 * |
113 * // add child element information item |
114 * // add child element information item |
114 * gcl.add(ObjectFactory.createLetterBodyName("Robert Smith")); |
115 * gcl.add(ObjectFactory.createLetterBodyName("Robert Smith")); |
117 * // add children element information items |
118 * // add children element information items |
118 * gcl.add(ObjectFactory. |
119 * gcl.add(ObjectFactory. |
119 * createLetterBodyQuantity(new BigInteger("1"))); |
120 * createLetterBodyQuantity(new BigInteger("1"))); |
120 * gcl.add(ObjectFactory.createLetterBodyProductName("Baby Monitor")); |
121 * gcl.add(ObjectFactory.createLetterBodyProductName("Baby Monitor")); |
121 * gcl.add("shipped from our warehouse"); // add text information item |
122 * gcl.add("shipped from our warehouse"); // add text information item |
122 * </pre> |
123 * }</pre> |
123 * |
124 * |
124 * <p>See "Package Specification" in javax.xml.bind.package javadoc for |
125 * <p>See "Package Specification" in javax.xml.bind.package javadoc for |
125 * additional common information.</p> |
126 * additional common information.</p> |
126 * @author Kohsuke Kawaguchi |
127 * @author Kohsuke Kawaguchi |
127 * @since 1.6, JAXB 2.0 |
128 * @since 1.6, JAXB 2.0 |