I found the answer, here on SO: Java : Simple XML not parsing the xml. Gives Exception
I had to add (inline=true)
to my ElementList
, as also shown in the tutorial.
質問
I have this XML string:
String str = "<order id='1234'><orderlines><orderline id='567'>"+
"<article id='890'><description>Bananen</description><todo>45</todo>"+
"</article></orderline></orderlines></order>";
that I want to read in using simple-framework version 2.7.1. It works OK until the orderline
class, which looks like this:
public class Orderline {
@Attribute
public int id;
@Element
public Article article;
}
I would expect the description
and todo
element to "go" into Article
, but I get this error:
05-08 22:45:23.958: D/debug(14854): Element 'description' does not have a match in class nl.rd.svgtest.Orderline at line 1
I parse like this:
Serializer s = new Persister();
Order o = s.read(Order.class, str);
adding false
to the s.read()
call has no effect.
解決
I found the answer, here on SO: Java : Simple XML not parsing the xml. Gives Exception
I had to add (inline=true)
to my ElementList
, as also shown in the tutorial.