How to Require XML Elements
By default, all XML elements in the generated schema are optional, unless the underlying Java type is a built-in type that does not allow null (such as int, boolean...). If you a value is required in an element, you must declare this explicitly:
public class Movie {
private String title;
private int releaseYear;
@XmlElement(required=true)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getReleaseYear() { // int is always required (more)
return releaseYear;
}
public void setReleaseYear(int releaseYear) {
this.releaseYear = releaseYear;
}
}
Resulting XML Schema fragment (the minOccurs attributes that made the elements optional have disappeared):
<xs:complexType name="movie">
<xs:sequence>
<xs:element name="releaseYear" type="xs:int"/>
<xs:element name="title" type="xs:string"/>
</xs:sequence>
</xs:complexType>

