【问题标题】:Java SimpleXml parsing @ElementListJava SimpleXml 解析@ElementList
【发布时间】:2013-08-19 11:48:40
【问题描述】:

我有这部分来自一个 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;

有可能吗?

【问题讨论】:

    标签: java xml-parsing simple-framework


    【解决方案1】:

    像这样使用@Text

    class Image {
    
    @Attribute
    int height;
    
    @Text
    String image
    }
    

    【讨论】:

    • 我也遇到了同样的问题,看了这么久。谢谢。
    猜你喜欢
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多