android 上的 simpleframework xml 和 @ElementList for kml 的问题

发布于 2024-12-03 04:19:31 字数 1891 浏览 5 评论 0原文

我似乎无法弄清楚这一点 - 非常感谢任何帮助!

我正在使用 simple-xml-2.3.2.jar 和 android v10

所以我有这个 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>

我已经制作了这些类来反序列化它:

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;
}

如果我运行它,我得到:org.simpleframework.xml.core.ElementException:元素“Placemark”在第-1行没有匹配

如果我用@Element替换Document.java中的@ElementList那么就可以了,但是当然仅当有一个子地标元素时!

多谢, 戴夫

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 deserializing 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随遇而安 2024-12-10 04:19:31

我刚刚遇到了同样的问题。尝试将 entry="Placemark" 添加到 ElementList 注释:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文