Mathias Conradt
Mathias Conradt

Reputation: 28695

SimpleXML: Element declared twice

I try to parse an xml with the SimpleXML lib, and I'm getting the following exception; can't figure out why it's complaining when I have my waters defined as a list. Probably something very basic I'm overlooking, but I just can't find it. I'm pretty much following the pattern of the example given on http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#list

btw: there's a similar question here on StackOverflow, but it's a different case, not actually dealing with ElementLists. In my case, I definitely want an ElementList and therefore would assume, the multiple existance of my element should actually be ok.

Error log:

Error parsing xml.
        org.simpleframework.xml.core.PersistenceException: Element 'gewaessereintrag' declared twice at line 9
        at org.simpleframework.xml.core.Variable$Adapter.read(Variable.java:456)
....

XML:

<?xml version="1.0" ?>
<gewaesser>
    <returncode>0</returncode>
    <gewaessereintrag>
        <id>1</id>
        <name><![CDATA[Entry1]]></name>
        <info><![CDATA[Info1.]]></info>
    </gewaessereintrag>
    <gewaessereintrag>
        <id>2</id>
        <name><![CDATA[Entry2]]></name>
        <info><![CDATA[Info2.]]></info>
    </gewaessereintrag>
</gewaesser>

WaterList (handling <gewaesser>):

@Root(name = "gewaesser")
public class WaterList {

    @ElementList(type = Water.class, name = "gewaessereintrag")
    private List<Water> waters;

    @Element(name = "returncode")
    private String returncode;

    public List<Water> getWaters() {
        return waters;
    }
}

Water (handling <gewaessereintrag>):

@Root(name = "gewaessereintrag")
public class Water {

    @Element(required = false, name = "name")
    private String name;

    @Element(required = false, name = "info")
    private String info;

    @Element(required = false, name = "id", type = Long.class)
    private Long id;

}

Upvotes: 3

Views: 1207

Answers (1)

Mathias Conradt
Mathias Conradt

Reputation: 28695

I just found the answer myself, but maybe this is helpful for others:

I forgot to declare "inline = true"

@ElementList(type = Water.class, name = "gewaessereintrag", inline = true)

Upvotes: 4

Related Questions