2.2.7
Defining a List of Integers
To obtain a simple type that can be used for XML element values as well as
for attribute values consisting of a simple series of values, use an
xsd:list
, as shown below.
<xsd:simpleType name="NumberListType">
<xsd:list itemType="xsd:int"/>
</xsd:simpleType>
The Java type used for this schema type will be
List<Integer>
, so again no Java class has to be
generated for this simple type. Using NumberListType
as an attribute or child type results in an instance variable and
a getter method in the parent class:
public class ListsType {
// ...
protected List<Integer> numbers;
// ...
public List<Integer> getNumbers() {
if (numbers == null) {
numbers = new ArrayList<Integer>();
}
return this.numbers;
}
// ...
}
The code in the getter method ensures that the List<Integer>
is created. There is no corresponding setter which means that all additions
or deletions of list elements have to be made on the "live" list.