开发者

problem with simpleframework xml and @ElementList for kml on android

I can't seem to get to the bottom of this - any help much appreciated!

I am using simple-xml-2.3.2.jar with android v10

So I have this xml (kml):

<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>Admissions</name>
<description>60.59</description>
<Polygon><tessellate>1</tessellate><outerBoundaryIs>
<LinearRing>
<coordinates>-1.1949914,52.93765,0 -1.1946743,52.937794,0 -1.1946228,52.93776,0 -1.1936871,52.938156,0 -1.19373,52.93821,0 -1.1933881,52.93836,0 -1.1935841,52.938503,0 -1.19424,52.938213,0 -1.1951548,52.93781,0 -1.1949914,52.93765,0</coordinates>
</LinearRing>
</outerBoundaryIs></Polygon>
</Placemark>
</Document>
</kml>

And I have made these classes for deserial开发者_JAVA百科izing it:

KML.java

import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

@Root(name="kml",strict=false)
public class KML {
    @Element(required=true,name="Document")
    public Document document;
}

Document.java

import java.util.List;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;

@Element
public class Document {
    @ElementList(required=false,inline=true)
    public List<Placemark> placemarkList;
}

Placemark.java

import java.util.List;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;

@Element
public class Placemark {
    @Element(required=false)
    public String name;

    @Element(required=false)
    public String description;

    @Element(required=false,name="Polygon")
    public Polygon polygon;
}

etc

If I run that I get: org.simpleframework.xml.core.ElementException: Element 'Placemark' does not have a match at line -1

If I replace the @ElementList in Document.java with an @Element then that works, but of course only where there is one child Placemark elements!

Thanks a lot, Dave


I just had the same problem. Try adding entry="Placemark" to the ElementList annotation:

@Element
public class Document {
    @ElementList(inline=true, entry="Placemark", required=false)
    public List<Placemark> placemarkList;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜