In this section we marshal a Java representation of an XML document constructed using the compiled Java classes to an XML document. Create the Java class by going to File | New | Other and selecting Java | Class. Provide a JAXB context for implementing the JAXB framework with a JAXBContext
object. Create a Marshaller
object from the JAXBContext
object and set the jaxb.formatted.output
to true
. The newInstance()
static method of the JAXBContext
class takes a list of packages, separated by a colon (:), that are to be added to the JAXB context. A package to be added to the JAXB context must contain either an ObjectFactory
class or a jaxb.index
file. As we compile the catalog.xsd
XML Schema into the jaxbeclipse
package, add the package to JAXB context. Create a Marshaller
object using the createMarshaller()
method of JAXBContext
, as follows:
JAXBContext jaxbContext = JAXBContext.newInstance("jaxbeclipse"); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller...