gpt4 book ai didi

Java SimpleXml 解析@ElementList

转载 作者:行者123 更新时间:2023-12-04 04:45:25 25 4
gpt4 key购买 nike

我从一个 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

我怎样才能用注释做到这一点?

更新:

不是我想要的,我有这样的课。
但我只想声明一个属性
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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com