我正在使用xjc而没有关于以下架构的参数:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:abc="http://someurl.com/schemas"
elementFormDefault="qualified"
targetNamespace="http://someurl.com/schemas">
<xs:element name="MyResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="addedUsers" type="abc:addedUsersType" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="addedUsersType">
<xs:sequence>
<xs:element name="user" type="abc:userType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="userType">
<xs:sequence>
<xs:element name="emailAddress" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="successfullyAdded" type="xs:boolean" maxOccurs="1" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>
它产生:
package com.someurl.schemas;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "addedUsersType", propOrder = {
"user"
})
public class AddedUsersType {
@XmlElement(required = true)
protected UserType user;
public UserType getUser() {
return user;
}
public void setUser(UserType value) {
this.user = value;
}
}
答案 0 :(得分:3)
如果未指定maxOccurs
,则默认值为1
。这就是该属性不是作为List
生成的原因。
要获得List
,您需要在元素定义上指定maxOccurs
属性,其值至少为2
:
<xs:element name="user" type="abc:userType" maxOccurs="2"/>
或unbounded
:
<xs:element name="user" type="abc:userType" maxOccurs="unbounded"/>