有意义的容器元素示例 [英] Example of meaningful container elements
本文介绍了有意义的容器元素示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它的用途是什么
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?
示例:
<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>
推荐答案
您可以像这样构造您的类:
You can structure your classes like this:
图书馆是根,
@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;
}
其中包含书籍列表:
@XmlAccessorType(XmlAccessType.FIELD)
public class Book {
@XmlAttribute(name = "isbn")
private String isbn;
private String title;
}
如果您尝试使用这些类解组所提供的xml,那么您将成功.
If you try to unmarshal the provided xml using these classes, you will be successful.
这篇关于有意义的容器元素示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文