VTD-XML产生“XML未正确终止”解析 KML 文件时出错
我从学校的班车跟踪服务器获取包含班车路线和位置的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能的情况是
只能得到任意数量的字节,但绝对不是整个文档......
您可以通过打印出返回值来验证
读取整个文档后,您应该使用 setDoc(doc, 0, length),0 是 doc 的起始偏移量,length 是 xml 文档的长度。
It may be the case that
only get you an arbitrary number of bytes, but definitely not the entire document...
you can verify that by printing out the returned value
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.