background image

Modify Marshal Example

<< Basic JAXB Examples | Building and Running the Example >>
<< Basic JAXB Examples | Building and Running the Example >>

Modify Marshal Example

address.setState(
"CA" );
address.setZip( new BigDecimal(
"90210" ) );
5. A Marshaller instance is created, and the updated XML content is marshalled to
system.out
. The setProperty API is used to specify output encoding; in this case
formatted (human readable) XML format.
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal( po, System.out );
Building and Running the Modify Marshal Example Using NetBeans IDE
Follow these instructions to build and run the Modify Marshal example on your Application
Server instance using the NetBeans IDE.
1. In NetBeans IDE, select File
Open Project.
2. In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/jaxb/.
3. Select the modify-marshal folder.
4. Select the Open as Main Project check box.
5. Click Open Project Folder.
6. Right-click the modify-marshal project and select Run Project.
Building and Running the Modify Marshal Example Using Ant
To compile and run the Modify Marshal example using Ant, in a terminal window, go to the
tut-install/javaeetutorial5/examples/jaxb/modify-marshal/ directory and type the
following:
ant runapp
Unmarshal Validate Example
The Unmarshal Validate example demonstrates how to enable validation during
unmarshalling. Note that JAXB provides functions for validation during unmarshalling but not
during marshalling. Validation is explained in more detail in
"More about Validation" on
page 492
.
1. The
tut-install/javaeetutorial5/examples/jaxb/unmarshal-validate/src/unmarshalvalidate/Main.java
class declares imports for three standard Java classes plus seven JAXB binding framework
classes and the primer.po package:
Basic JAXB Examples
The Java EE 5 Tutorial · September 2007
512