Simple Xml list parsing problem

Posted by Hubidubi on Stack Overflow See other posts from Stack Overflow or by Hubidubi
Published on 2011-08-05T13:06:49Z Indexed on 2012/11/01 23:01 UTC
Read the original article Hit count: 502

I have this xml:

<root>
<fruitlist>
    <apple>4</apple>
    <apple>5</apple>
    <orange>2</orange>
    <orange>6</orange>
</fruitlist>
</root>

I'm writing a parser class, although I can't figure out how to deal with multiple node types. I can easily parse a list that contains only one node type (eg. just apples, not oranges)

@ElementList(name = "fruitlist")
private List<Apple> exercises;

with more than one node type it also wants so parse non Apple nodes which doesn't work. I also tried to make another list for oranges, but it doen't work, I can't use fruitlist name more than once.

@ElementList(name = "fruitlist", entry = "orange")
private List<Orange> exercises;

The ideal would be two seperate list for both node types.

Hubi

EDIT: After more searching & fiddling this question is a duplicate:

Inheritance with Simple XML Framework

© Stack Overflow or respective owner

Related posts about java

Related posts about android