1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
<!-- * Copyright © 2007 Sun Microsystems,
3
Inc. All rights reserved.
4
Use is subject to license terms. *-->
7
<title>Marshalling Java Classes to XML Elements</title>
8
<link rel="stylesheet" href="nbdocs://org.netbeans.modules.usersguide/org/netbeans/modules/usersguide/ide.css" type="text/css">
11
<h2>Marshalling Java Classes to XML Elements</h2>
12
<p> <small><a href="#seealso">See Also</a> </small>
13
<p>The <a href="about_jaxb.html">Java Architecture for XML Binding API (JAXB)</a> provides a client application
14
the ability to convert Java classes into a
15
hierarchy of XML elements. The IDE provides a code template
16
that you can use to generate a code
17
snippet as the basis for this task.
19
<p><b>To marshall Java classes to XML elements:</b>
23
<li>Type <tt>jaxbm</tt> in
24
the Source Editor for Java files
25
and then press Tab. The snippet is
28
javax.xml.bind.JAXBContext jaxbCtx= javax.xml.bind.JAXBContext.newInstance( Object.class.getClass().getPackage().getName());
29
javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
30
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); //NOI18N
31
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
32
marshaller.marshal(Object.class , System.out);
33
} catch (javax.xml.bind.JAXBException ex) {
34
// XXXTODO Handle exception
35
java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); //NOI18N
38
incorporate it in the rest of your code.
44
<dt><a name="seealso">See Also</a></dt>
45
<dd><a href="about_jaxb.html">About Mapping XML to Java</a></dd>
46
<dd><a href="jaxb_wizard.html">Generating Java Classes from XML Schema Documents</a></dd>
50
<small><a href="../../credits.html">Legal Notices</a>
51
<table cellpadding="20" border="0">
52
<tr><td> </td></tr>
53
<tr><td> </td></tr>
54
<tr><td> </td></tr>
56
</small></body></html>