Women in Technology

Hear us Roar

  Generating an XML Document with JAXB
Subject:   JAXB 2.0
Date:   2006-03-19 07:16:16
From:   dvohra09
For JAXB 2.0 the JAR files required and the Java classes generated are different.

1. JAXB 2.0 requires JDK 5.0, because JAXB 2.0 makes use of parameterized types.

2. For JAXB 2.0 the JAR files required are :

C:\Sun\jwsdp-2.0\jaxb\lib\jaxb-api.jar, C:\Sun\jwsdp-2.0\jaxb\lib\jaxb-impl.jar, C:\Sun\jwsdp-2.0\jaxb\lib\jaxb-xjc.jar, C:\Sun\jwsdp-2.0\jwsdp-shared\lib\activation.jar,
C:\Sun\jwsdp-2.0\sjsxp\lib\jsr173_api.jar, C:\Sun\jwsdp-2.0\sjsxp\lib\sjsxp.jar

3. For JAXB 2.0 a value class is generated for each top level complexType, instead of an interface and a implementation class. An ObjectFactory method is generated for each op level element.

4. For marshalling with JAXB 2.0, marshall with JAXBElement<CatalogType> object, instead of CatalogType object. CatalogType is value class corresponding to root element complexType catalogType.
//Create a CatalogType object
CatalogType catalog = factory.createCatalogType();
//Add elements and attributes to CatalogType object.
//Obtain a JAXBElement object from CatalogType object and marshall with the JAXBElement element.
JAXBElement<CatalogType> catalogElement=factory.createCatalog(catalog);
marshaller.marshal(catalogElement, new FileOutputStream(xmlDocument));

5. For unmarshalling with JAXB 2.0, unmarshalling returns a JAXBElement object.

JAXBContext jaxbContext = JAXBContext.newInstance("generated");
Unmarshaller unMarshaller = jaxbContext.createUnmarshaller();
JAXBElement<CatalogType> catalogElement = (JAXBElement<CatalogType>)

//Obtain a CatalogType object from JAXBElement object.

CatalogType catalog=catalogElement.getValue();

Main Topics Oldest First

Showing messages 1 through 2 of 2.

  • JAXB1.4 | Root element of the schema is not created
    2006-07-26 23:37:45  Gowtham_J [View]

    Hi Deepak, I am working on JXB1.4 to create the XML document by binding the XML schema. Everything is fine except the Root element generation. My root element is not at all created. For marshalling, i am giving the root element object. But it didnt worked. what could be the reason/reasons???
    Hope you can help me to get rid of this problem.

    Thanks in advance.

    Gowtham J

  • JAXB 2.0
    2006-07-20 09:05:18  gpaladi [View]

    I tried all steps you have mentioned for JAXB 2.0. But when I run XJC, it's not creating all classes. I try to ran the sample catalog.xsd you have mentioned in the article. It created only the following 4 files.

    Can you please help to fix this problem.