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?
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.