如果schema定義如下
<xs:element name="PhysicalAddress">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="1">
<xs:element minOccurs="0" maxOccurs="1" ref="addressLine1" />
<xs:element minOccurs="0" maxOccurs="1" ref="addressLine2" />
<xs:element minOccurs="0" maxOccurs="1" ref="addressLine3" />
<xs:element minOccurs="0" maxOccurs="1" ref="cityName" />
<xs:element minOccurs="0" maxOccurs="1" ref="GlobalCountryCode" />
<xs:element minOccurs="0" maxOccurs="1" ref="GlobalLocationIdentifier" />
<xs:element minOccurs="0" maxOccurs="1" ref="NationalPostalCode" />
<xs:element minOccurs="0" maxOccurs="1" ref="postOfficeBoxIdentifier" />
<xs:element minOccurs="0" maxOccurs="1" ref="regionName" />
</xs:sequence>
</xs:complexType>
</xs:element>
生成的java類結果如下
[quote]
public class PhysicalAddress {
protected AddressLine1 addressLine1;
protected AddressLine2 addressLine2;
protected AddressLine3 addressLine3;
protected CityName cityName;
protected String globalCountryCode;
protected String globalLocationIdentifier;
protected String nationalPostalCode;
protected PostOfficeBoxIdentifier postOfficeBoxIdentifier;
protected RegionName regionName;
}
[/quote]
但是,如下的schema結構
<xs:element name="PartnerBusinessIdentification">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="ProprietaryBusinessIdentifier" />
<xs:element ref="ProprietaryDomainIdentifier" />
<xs:element minOccurs="0" maxOccurs="1" ref="ProprietaryIdentifierAuthority" />
</xs:sequence>
</xs:complexType>
</xs:element>
生成的java類卻如下所示,可以忽略@XMLElementRef(s)的註釋暫時不用管
[quote]
public class PartnerBusinessIdentification {
@XmlElementRefs({
@XmlElementRef(name = "ProprietaryBusinessIdentifier", type = JAXBElement.class),
@XmlElementRef(name = "ProprietaryDomainIdentifier", type = JAXBElement.class),
@XmlElementRef(name = "ProprietaryIdentifierAuthority", type = JAXBElement.class)
})
protected List<JAXBElement<String>> proprietaryBusinessIdentifierAndProprietaryDomainIdentifierAndProprietaryIdentifierAuthority;
}
[/quote]
我就不明白爲什麼不是生成以下這樣的類結構呢?
[quote]
public class PartnerBusinessIdentification {
protected ProprietaryBusinessIdentifier proprietaryBusinessIdentifier;
protected ProprietaryDomainIdentifier proprietaryDomainIdentifier;
protected ProprietaryIdentifierAuthority proprietaryIdentifierAuthority;
}
[/quote]
後來比較多個類似結構的schema發現,問題應該是在<xs:sequence>上,[b]如果它加上了maxOccurs="unbounded"屬性的話,就只會在此元素對應的java類中生成一個List<?>類型的元素,而不管裏面<xs:sequence>究竟有一個還是多個子元素[/b],這樣一來生成的java類就非常難處理了。我正在想對策中