Search code examples
javaxmlsimple-framework

SimpleXML: How to read XML content as list?


Assume we have this xml input:

<list>
   <id>1</id>
   <id>2</id>
   <id>3</id>
</list>

How can can I decode the id-content into a list? Like this:

 @ElementList
 List<Integer> ids;

This doesn't work, it seems @ElementList only works for attributes.Is there an other way to achive it?


Solution

  • You can achieve this using inline and entry on the @ElementList annotation

    @ElementList(entry = "id", inline = true, required = false)
    List<Integer> ids;