July 31, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Using JAXB in JDeveloper 10.1.3

  • January 17, 2008
  • By Deepak Vohra
  • Send Email »
  • More Articles »

JAXBMarshaller.java is listed below.

package jaxb;
import java.io.*;
import javax.xml.bind.*;
import oracle.xml.jaxb.JaxbContextImpl;
public class JAXBMarshaller
{
   public void createXMLDocument(File xmlDocument){
      try
      {

         JaxbContextImpl jaxbContext=new JaxbContextImpl();
         Marshaller marshaller=jaxbContext.createMarshaller();

         ObjectFactory factory=new ObjectFactory();
         Catalog catalog=factory.createCatalog();
         catalog.setTitle("Oracle Magazine");
         catalog.setPublisher("Oracle Publishing");

         JournalType journal=factory.createJournalType();
         journal.setDate("July-August 2005");

         ArticleType article=factory.createArticleType();
         article.setSection("Technology");
         article.setTitle("Tuning Undo Tablespace");
         article.setAuthor("Kimberly Floss");

         java.util.List articleList=journal.getArticle();
         articleList.add(article);

         java.util.List journalList=catalog.getJournal();
         journalList.add(journal);

         journal=factory.createJournalType();
         journal.setDate("July-August 2005");

         article=factory.createArticleType();
         article.setSection("Technology");
         article.setTitle("Using PHP 5 with Oracle XML DB");
         article.setAuthor("Yuli Vasiliev");

         articleList=journal.getArticle();
         articleList.add(article);

         journalList=catalog.getJournal();
         journalList.add(journal);

         marshaller.marshal(catalog, new
            FileOutputStream(xmlDocument));

      }catch (IOException e)
      {
         System.out.println(e.toString());

      }
      catch (JAXBException e)
      {
         System.out.println(e.toString());

      }

   }
   public static void main (String[] argv)
   {
      JAXBMarshaller marshaller=new JAXBMarshaller();
      marshaller.createXMLDocument(new File("catalog.xml"));
   }
}

To run the JAXBMarshaller application, right-click JAXBMarshaller.java in Applications Navigator and select Run.



Click here for a larger image.

Figure 6: Running JAXB Application

The Java object constructed gets marshaled to an XML document, as shown below.



Click here for a larger image.

Figure 7: XML Document Marshalled using JAXB





Page 4 of 6



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel