VTD-XML产生“XML未正确终止”解析 KML 文件时出错

发布于 2024-10-15 18:33:12 字数 580 浏览 3 评论 0原文

我从学校的班车跟踪服务器获取包含班车路线和位置的 KML 文件。我想在 Android 应用程序中解析此 KML,但当我将文件传递到 VTD-XML 2.9 解析器时,它失败,告诉我 XML 未正确终止。我通过架构验证器运行了该文件,尽管它不符合 KML 2.1架构(不喜欢文件夹元素),它的格式良好。

我不认为该文档有任何其他问题,但我也看不出我的代码可能存在问题:

byte[] doc = new byte[32000];
URL url = new URL("http://shuttles.rpi.edu/displays/netlink.kml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream is = conn.getInputStream();
is.read(doc);

VTDGen vg = new VTDGen();
vg.setDoc(doc);
vg.parse(true);

I'm getting a KML file containing shuttle routes and positions from my school's shuttle tracking server. I want to parse this KML in my Android application, but when I pass the file into the VTD-XML 2.9 parser, it fails, telling me that the XML is not properly terminated. I ran the file through a schema validator and although it doesn't conform to the KML 2.1 Schema (doesn't like the folder element), it is well-formed.

I don't think there's anything else wrong with the document, but I also don't see where there could be a problem with my code:

byte[] doc = new byte[32000];
URL url = new URL("http://shuttles.rpi.edu/displays/netlink.kml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream is = conn.getInputStream();
is.read(doc);

VTDGen vg = new VTDGen();
vg.setDoc(doc);
vg.parse(true);

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

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

发布评论

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

评论(1

最初的梦 2024-10-22 18:33:12

可能的情况是

is.read(doc); 

只能得到任意数量的字节,但绝对不是整个文档......
您可以通过打印出返回值来验证

int k = is.read(doc)

读取整个文档后,您应该使用 setDoc(doc, 0, length),0 是 doc 的起始偏移量,length 是 xml 文档的长度。

It may be the case that

is.read(doc); 

only get you an arbitrary number of bytes, but definitely not the entire document...
you can verify that by printing out the returned value

int k = is.read(doc)

After reading the entire document, you should use setDoc(doc, 0, length), 0 is the starting offset wrt to the doc, length is length of xml document.

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