有意义的容器元素示例

Example of meaningful container elements

有什么用:

https://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/XmlElementWrapper.html

以便 "collection of collections" 能够以标准可接受的方式编程创建?

IBM pdf with sample

示例:

<library>
<name>The XML Institute Public Library</name>
<endowment>
<donor>IBM</donor>
<book isbn="0764547607">
<title>The XML Bible, 2nd Edition</title>
</book>
<book isbn="0321150406">
<title>Effective XML</title>
</book>
</endowment>
<endowment>
<donor>W3C</donor>
<book isbn="1861005946">
<title>Beginning XSLT</title>
</book>
</endowment>

您可以像这样构建您的 类:

图书馆是根,

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Library {

    private String name;
    private List<Endowment> endowment;
}

其中包含捐赠清单:

@XmlAccessorType(XmlAccessType.FIELD)
public class Endowment {

    private String donor;
    private List<Book> book;
}

其中包含书籍列表:

@XmlAccessorType(XmlAccessType.FIELD)
public class Book {

    @XmlAttribute(name = "isbn")
    private String isbn;
    private String title;
}

如果您尝试使用这些 类 解组提供的 xml,您将会成功。