简体   繁体   中英

Java SimpleXml parsing @ElementList

I have this part from an Xml file:

<image height="55">image1.jpg</image>
<image height="60">image2.jpg</image>
<image height="170">image3.jpg</image>

I know that I can parse it with :

@ElementList(entry = "image", inline = true)
private List<Image> images;

but I need in my java object one attribute with the name :

String image; // correspond to image2.jpg

How can I do this with annotation ?

Update:

It's not that I want, I have a class like this. But I want to declare only one attribute

String image;

to access directly to the text from the second line with direct annotation

<image height="60">image2.jpg</image>

for example (I don't know) something like this :

@Element(name="image[1]/text")
String image;

Is it possible ?

Use @Text like this

class Image {

@Attribute
int height;

@Text
String image
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM