71 * |
71 * |
72 * <p> |
72 * <p> |
73 * Unmarshalling from a StringBuffer using a |
73 * Unmarshalling from a StringBuffer using a |
74 * <tt>javax.xml.transform.stream.StreamSource</tt>: |
74 * <tt>javax.xml.transform.stream.StreamSource</tt>: |
75 * <blockquote> |
75 * <blockquote> |
76 * <pre> |
76 * <pre>{@code |
77 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); |
77 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); |
78 * Unmarshaller u = jc.createUnmarshaller(); |
78 * Unmarshaller u = jc.createUnmarshaller(); |
79 * StringBuffer xmlStr = new StringBuffer( "<?xml version="1.0"?>..." ); |
79 * StringBuffer xmlStr = new StringBuffer( "<?xml version="1.0"?>..." ); |
80 * Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) ); |
80 * Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) ); |
81 * </pre> |
81 * }</pre> |
82 * </blockquote> |
82 * </blockquote> |
83 * |
83 * |
84 * <p> |
84 * <p> |
85 * Unmarshalling from a <tt>org.w3c.dom.Node</tt>: |
85 * Unmarshalling from a <tt>org.w3c.dom.Node</tt>: |
86 * <blockquote> |
86 * <blockquote> |
236 * Additionally, when the root element of XML data has an <tt>xsi:type</tt> attribute and |
236 * Additionally, when the root element of XML data has an <tt>xsi:type</tt> attribute and |
237 * that attribute's value references a type definition that is mapped |
237 * that attribute's value references a type definition that is mapped |
238 * to a JAXB mapped class by {@link JAXBContext}, that the root |
238 * to a JAXB mapped class by {@link JAXBContext}, that the root |
239 * element's <tt>xsi:type</tt> attribute takes |
239 * element's <tt>xsi:type</tt> attribute takes |
240 * precedence over the unmarshal methods <tt>declaredType</tt> parameter. |
240 * precedence over the unmarshal methods <tt>declaredType</tt> parameter. |
241 * These methods always return a <tt>JAXBElement<declaredType></tt> |
241 * These methods always return a <tt>{@literal JAXBElement<declaredType>}</tt> |
242 * instance. The table below shows how the properties of the returned JAXBElement |
242 * instance. The table below shows how the properties of the returned JAXBElement |
243 * instance are set. |
243 * instance are set. |
244 * |
244 * |
245 * <a name="unmarshalDeclaredTypeReturn"></a> |
245 * <a name="unmarshalDeclaredTypeReturn"></a> |
246 * <table summary="" border="2" rules="all" cellpadding="4"> |
246 * <table summary="" border="2" rules="all" cellpadding="4"> |
279 * The following is an example of |
279 * The following is an example of |
280 * <a href="#unmarshalByDeclaredType">unmarshal by declaredType method</a>. |
280 * <a href="#unmarshalByDeclaredType">unmarshal by declaredType method</a>. |
281 * <p> |
281 * <p> |
282 * Unmarshal by declaredType from a <tt>org.w3c.dom.Node</tt>: |
282 * Unmarshal by declaredType from a <tt>org.w3c.dom.Node</tt>: |
283 * <blockquote> |
283 * <blockquote> |
284 * <pre> |
284 * <pre>{@code |
285 * Schema fragment for example |
285 * Schema fragment for example |
286 * <xs:schema> |
286 * <xs:schema> |
287 * <xs:complexType name="FooType">...<\xs:complexType> |
287 * <xs:complexType name="FooType">...<\xs:complexType> |
288 * <!-- global element declaration "PurchaseOrder" --> |
288 * <!-- global element declaration "PurchaseOrder" --> |
289 * <xs:element name="PurchaseOrder"> |
289 * <xs:element name="PurchaseOrder"> |
290 * <xs:complexType> |
290 * <xs:complexType> |
291 * <xs:sequence> |
291 * <xs:sequence> |
292 * <!-- local element declaration "foo" --> |
292 * <!-- local element declaration "foo" --> |
293 * <xs:element name="foo" type="FooType"/> |
293 * <xs:element name="foo" type="FooType"/> |
294 * ... |
294 * ... |
295 * </xs:sequence> |
295 * </xs:sequence> |
296 * </xs:complexType> |
296 * </xs:complexType> |
297 * </xs:element> |
297 * </xs:element> |
298 * </xs:schema> |
298 * </xs:schema> |
299 * |
299 * |
300 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); |
300 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); |
301 * Unmarshaller u = jc.createUnmarshaller(); |
301 * Unmarshaller u = jc.createUnmarshaller(); |
302 * |
302 * |
303 * DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
303 * DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
306 * Document doc = db.parse(new File( "nosferatu.xml")); |
306 * Document doc = db.parse(new File( "nosferatu.xml")); |
307 * Element fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a |
307 * Element fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a |
308 * // local element declaration in schema. |
308 * // local element declaration in schema. |
309 * |
309 * |
310 * // FooType is the JAXB mapping of the type of local element declaration foo. |
310 * // FooType is the JAXB mapping of the type of local element declaration foo. |
311 * JAXBElement<FooType> foo = u.unmarshal( fooSubtree, FooType.class); |
311 * JAXBElement<FooType> foo = u.unmarshal( fooSubtree, FooType.class); |
312 * </pre> |
312 * }</pre> |
313 * </blockquote> |
313 * </blockquote> |
314 * |
314 * |
315 * <p> |
315 * <p> |
316 * <b>Support for SAX2.0 Compliant Parsers</b><br> |
316 * <b>Support for SAX2.0 Compliant Parsers</b><br> |
317 * <blockquote> |
317 * <blockquote> |