如果我有如下的架构:
<xs:element name="Book">
<xs:complexType>
<xs:sequence>
<xs:element ref="Chapter" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Chapter">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Word" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Word">
</xs:element>
Run Code Online (Sandbox Code Playgroud)
它将生成类似于:
@XmlRootElement(name = "Book")
public class Book {
@XmlElement(name = "Chapter", required = true)
protected Chapter chapter;
Run Code Online (Sandbox Code Playgroud)
是否有可能生成以下内容?
@XmlElement(name = "Chapter", required = true)
protected Chapter chapter = new Chapter();
Run Code Online (Sandbox Code Playgroud)
这样,即使XML文件缺少Book中的Chapter元素,当它被解组时仍然会创建一个Book对象,因此可以执行book.getChapter().getWord()并检索一个空列表而不是检查null.
归档时间: |
|
查看次数: |
277 次 |
最近记录: |