我从 Xml 文件中获取了这部分:
<image height="55">image1.jpg</image>
<image height="60">image2.jpg</image>
<image height="170">image3.jpg</image>
我知道我可以用以下方式解析它:
@ElementList(entry = "image", inline = true)
private List<Image> images;
但我需要在我的 java 对象中使用一个属性,其名称为:
String image; // correspond to image2.jpg
如何使用注释来做到这一点?
更新:
这不是我想要的,我有这样的类(class)。 但我只想声明一个属性
String image;
通过直接注释直接访问第二行的文本
<image height="60">image2.jpg</image>
例如(我不知道)这样的事情:
@Element(name="image[1]/text")
String image;
可能吗?
最佳答案
像这样使用@Text
class Image {
@Attribute
int height;
@Text
String image
}
关于Java SimpleXml 解析@ElementList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18284022/