Wednesday, June 06, 2012

Generate JAVA File from XSD using XJC Tool (JAXB)

Hello world xsd file :






     

 
  
      

 
 

 
  
   
   
   
   
  

 
  
   
   
   
  



Then Initiate the command from command line : Generated class files are :
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2012.06.06 at 11:37:48 AM ALMT 
//


package com.helloworld;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * 

Java class for anonymous complex type. * *

The following schema fragment specifies the expected content contained within this class. * *

 * <complexType>
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="hackername" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         <element name="hackercode" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         <element name="expcode" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *       </sequence>
 *     </restriction>
 *   </complexContent>
 * </complexType>
 * 
* * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "hackername", "hackercode", "expcode" }) @XmlRootElement(name = "Hacker") public class Hacker { @XmlElement(required = true) protected String hackername; @XmlElement(required = true) protected String hackercode; @XmlElement(required = true) protected String expcode; /** * Gets the value of the hackername property. * * @return * possible object is * {@link String } * */ public String getHackername() { return hackername; } /** * Sets the value of the hackername property. * * @param value * allowed object is * {@link String } * */ public void setHackername(String value) { this.hackername = value; } /** * Gets the value of the hackercode property. * * @return * possible object is * {@link String } * */ public String getHackercode() { return hackercode; } /** * Sets the value of the hackercode property. * * @param value * allowed object is * {@link String } * */ public void setHackercode(String value) { this.hackercode = value; } /** * Gets the value of the expcode property. * * @return * possible object is * {@link String } * */ public String getExpcode() { return expcode; } /** * Sets the value of the expcode property. * * @param value * allowed object is * {@link String } * */ public void setExpcode(String value) { this.expcode = value; } }
And :
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2012.06.06 at 11:37:48 AM ALMT 
//


package com.helloworld;

import javax.xml.bind.annotation.XmlRegistry;


/**
 * This object contains factory methods for each 
 * Java content interface and Java element interface 
 * generated in the com.helloworld package. 
 * 

An ObjectFactory allows you to programatically * construct new instances of the Java representation * for XML content. The Java representation of XML * content can consist of schema derived interfaces * and classes representing the binding of schema * type definitions, element declarations and model * groups. Factory methods for each of these are * provided in this class. * */ @XmlRegistry public class ObjectFactory { /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.helloworld * */ public ObjectFactory() { } /** * Create an instance of {@link Hacker } * */ public Hacker createHacker() { return new Hacker(); } }

And final one :
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2012.06.06 at 11:37:48 AM ALMT 
//

@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.helloworld.com", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.helloworld;




No comments:

Post a Comment