Thomas T. Thomas T. - 3 months ago 8
Java Question

XML converter handle EmptyList

I'm trying to use the simpleframework converter to convert this XML :

<?xml version="1.0" encoding="UTF-8" ?>
<dvds generator="$Id: dvd.tpl 855 2008-08-04 15:53:24Z glapierre $"></dvds>


To those classes :

@Root
public class SearchResult {
@Attribute(name = "generator")
private String generator;
@ElementList(entry = "dvd", inline = true, required = false, empty = true)
private List<DVDResult> dvds;

public SearchResult() {}

public List<DVDResult> getDVDs() {
return dvds;
}

public String getGenerator() {
return generator;
}
}

@Root
public class DVDResult {
// Some @Element with getters
}


When the list is not empty there is no problem but in this particular case I get a
org.simpleframework.xml.stream.NodeException: Document has no root element
and I really don't know why.

I thought that it was on my
@ElementList
so I had
entry
and
empty
but no changes. I also removed
name
from
@Root
s.

Does somebody have an answer to that?

Answer

Problem solved. It was my parsing which was over-complicated. I was using the SimpleXML factory, changed it to :

Serializer serializer = new Persister();
SearchResult result = serializer.read(SearchResult.class, myXMLString);
Comments