User.java - Java Data Type Class Generated by XJC

Q

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

✍: FYIcenter.com

A

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/User.java, 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;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "birthDate",
    "name",
    "sex"
})

@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) {
        this.name = value;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String value) {
        this.sex = value;
    }

    public int getID() {
        return id;
    }

    public void setID(int value) {
        this.id = 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.

 

Examples for JAXB (Java Architecture for XML Binding)

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

2018-05-08, 333👍, 0💬