Reference :http://www.xyzws.com/scdjws/studyguide/jaxb_samples2.0.html
1. command :
D:\xsd2Java\bin>xjc -p com.XXXX.g3.xml Service.xsd
parsing a schema...
compiling a schema...
com\XXXX\g3\xml\ObjectFactory.java
com\XXXX\g3\xml\Service.java
Note :xsd2Java is same as Java home (using java 1.7)
2. Input : Service.xsd
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
minOccurs="0">
3.Output :
ObjectFactory.java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.04.05 at 11:41:50 AM SGT
//
package com.xxxx.g3.xml;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the com.bcsis.g3.xml 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.bcsis.g3.xml
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link Service }
*
*/
public Service createService() {
return new Service();
}
/**
* Create an instance of {@link Service.ServiceType }
*
*/
public Service.ServiceType createServiceServiceType() {
return new Service.ServiceType();
}
/**
* Create an instance of {@link Service.ReportGeneration }
*
*/
public Service.ReportGeneration createServiceReportGeneration() {
return new Service.ReportGeneration();
}
}
Service.java:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.04.05 at 11:41:50 AM SGT
//
package com.xxxx.g3.xml;
import java.util.ArrayList;
import java.util.List;
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="Service-Type">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="type" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* <element name="ReportGeneration" maxOccurs="unbounded" minOccurs="0">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="reportId" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="reportGroupId" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="currencyCode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
*
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"serviceType",
"reportGeneration"
})
@XmlRootElement(name = "Service")
public class Service {
@XmlElement(name = "Service-Type", required = true)
protected Service.ServiceType serviceType;
@XmlElement(name = "ReportGeneration")
protected List
reportGeneration;
/**
* Gets the value of the serviceType property.
*
* @return
* possible object is
* {@link Service.ServiceType }
*
*/
public Service.ServiceType getServiceType() {
return serviceType;
}
/**
* Sets the value of the serviceType property.
*
* @param value
* allowed object is
* {@link Service.ServiceType }
*
*/
public void setServiceType(Service.ServiceType value) {
this.serviceType = value;
}
/**
* Gets the value of the reportGeneration property.
*
*
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a set
method for the reportGeneration property.
*
*
* For example, to add a new item, do as follows:
*
* getReportGeneration().add(newItem);
*
*
*
*
* Objects of the following type(s) are allowed in the list
* {@link Service.ReportGeneration }
*
*
*/
public List getReportGeneration() {
if (reportGeneration == null) {
reportGeneration = new ArrayList();
}
return this.reportGeneration;
}
/**
* 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="reportId" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="reportGroupId" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="currencyCode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
*
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"reportId",
"reportGroupId",
"currencyCode"
})
public static class ReportGeneration {
@XmlElement(required = true)
protected String reportId;
@XmlElement(required = true)
protected String reportGroupId;
@XmlElement(required = true)
protected String currencyCode;
/**
* Gets the value of the reportId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getReportId() {
return reportId;
}
/**
* Sets the value of the reportId property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setReportId(String value) {
this.reportId = value;
}
/**
* Gets the value of the reportGroupId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getReportGroupId() {
return reportGroupId;
}
/**
* Sets the value of the reportGroupId property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setReportGroupId(String value) {
this.reportGroupId = value;
}
/**
* Gets the value of the currencyCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCurrencyCode() {
return currencyCode;
}
/**
* Sets the value of the currencyCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCurrencyCode(String value) {
this.currencyCode = value;
}
}
/**
* 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="type" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
*
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"type",
"name"
})
public static class ServiceType {
@XmlElement(required = true)
protected String type;
@XmlElement(required = true)
protected String name;
/**
* Gets the value of the type property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getType() {
return type;
}
/**
* Sets the value of the type property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setType(String value) {
this.type = value;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
}
}
============== difference between xmlns:xsd and xmlns:xs=============
from w3.org
The XML representation of schema components uses a vocabulary identified by the namespace name http://www.w3.org/2001/XMLSchema. For brevity, the text and examples in this specification use the prefix xs: to stand for this namespace; in practice, any prefix can be used.
in the end xs or xsd are only prefixes. XSD is used for example more by Microsoft schemas.
The important is how you declare the namespace.
or
should be equivalent.
2. Equivalent Service.xsd using "