GeniDeveloper
GeniDeveloper

Reputation: 361

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 ?

Upvotes: 2

Views: 1541

Answers (1)

ng.
ng.

Reputation: 7189

Use @Text like this

class Image {

@Attribute
int height;

@Text
String image
}

Upvotes: 3

Related Questions