10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>The</strong> @XmlRootElement annotation maps a class or an enum type to an XML element. At least one<br />

element definition is needed for each top-level <strong>Java</strong> type used for unmarshalling/marshalling. If<br />

there is no element definition, there is no starting location for XML content processing.<br />

<strong>The</strong> @XmlRootElement annotation uses the class name as the default element name. You can<br />

change the default name by using the annotation attribute name. If you do, the specified name<br />

will then be used as the element name and the type name. It is common schema practice for the<br />

element and type names to be different. You can use the @XmlType annotation to set the element<br />

type name.<br />

<strong>The</strong> namespace attribute of the @XmlRootElement annotation is used to define a namespace for<br />

the element.<br />

Building and Running the XmlRootElement Example Using NetBeans<br />

IDE<br />

Follow these instructions to build and run the XmlRootElement example on your Application<br />

Server instance using NetBeans IDE.<br />

1. In NetBeans IDE, select File→Open Project.<br />

2. In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/jaxb/.<br />

3. Select the j2s-xmlRootElement folder.<br />

4. Select the Open as Main Project check box.<br />

5. Click Open Project.<br />

6. Right-click the j2s-xmlRootElement project and select Run.<br />

Building and Running the XmlRootElement Example Using Ant<br />

To compile and run the XmlRootElement example using Ant, in a terminal window, go to the<br />

tut-install/javaeetutorial5/examples/jaxb/j2s-xmlRootElement/ directory and type the<br />

following:<br />

ant runapp<br />

XmlSchemaType Class Example<br />

<strong>Java</strong>-to-Schema Examples<br />

<strong>The</strong> XmlSchemaType Class example demonstrates the use of the annotation @XmlSchemaType<br />

to customize the mapping of a property or field to an XML built-in type.<br />

<strong>The</strong> @XmlSchemaType annotation can be used to map a <strong>Java</strong> type to one of the XML built-in<br />

types. This annotation is most useful in mapping a <strong>Java</strong> type to one of the nine date/time<br />

primitive data types.<br />

Chapter 17 • Binding between XML Schema and <strong>Java</strong> Classes 543

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!