- Java Data Type Class Generated by XJC


How to read the Java code generated from XML Schema with XJC (XML to Java Compiler)?



To read the Java code generated from XML Schema with XJC (XML to Java Compiler), you can simply open it in any Java code development tool, or just a text edit.

For example, if you open the Java code, generated/, generated from the previous tutorial, you will see the following after removing all comments in the code:

package generated;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;

@XmlType(name = "", propOrder = {

@XmlRootElement(name = "User")
public class User {

    @XmlElement(name = "BirthDate", required = true)
    @XmlSchemaType(name = "date")
    protected XMLGregorianCalendar birthDate;
    @XmlElement(name = "Name", required = true)
    protected String name;
    @XmlElement(name = "Sex", required = true)
    protected String sex;
    @XmlAttribute(name = "ID", required = true)
    protected int id;

    public XMLGregorianCalendar getBirthDate() {
        return birthDate;

    public void setBirthDate(XMLGregorianCalendar value) {
        this.birthDate = value;

    public String getName() {
        return name;

    public void setName(String value) { = value;

    public String getSex() {
        return sex;

    public void setSex(String value) { = value;

    public int getID() {
        return id;

    public void setID(int value) { = value;

The generated Java code is very straightforward. The generated.User class is declared with protected properties for all child elements and attributes defined in for the "User" element in the user.xsd file.


XJC -p Option for Class Package Name

Generate Java Code from XML Schema with XJC

Examples for JAXB (Java Architecture for XML Binding)

⇑⇑ FAQ for jaxb-*.jar - Java Architecture for XML Binding

2018-05-08, 1394🔥, 0💬