1

What's the usage of:

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

so that a "collection of collections" can be created programatically in a standards acceptable fashion?

IBM pdf with sample

Example:

<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>
Thufir
  • 8,216
  • 28
  • 125
  • 273

1 Answers1

4

You can structure your classes like this:

Library is the root,

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

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

Which contains a list of endowments:

@XmlAccessorType(XmlAccessType.FIELD)
public class Endowment {

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

Which contain a list of Books:

@XmlAccessorType(XmlAccessType.FIELD)
public class Book {

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

If you try to unmarshal the provided xml using these classes, you will be successful.

martidis
  • 2,897
  • 1
  • 11
  • 13