VTD-XML produces "XML not terminated properly" error when parsing KML file

1.5k Views Asked by At

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);
1

There are 1 best solutions below

6
On BEST ANSWER

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.