KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm getting a "SAXParseException: Unexpected end of document" error when trying to parse an xml document on android. The document in question is from the google weather api, but it seems to throw the same error regardless of the xml file in question (as long as the xml is valid) so I suspect it's a problem with my approach, rather than the xml. This is being done as a learning exercise, so I've probably (hopefully) overlooked something obvious =) I've run the xml through an online validator, and it comes back as being well formed. (Can't tell me if it's valid as I don't have a DTD, but I dont think I need the DTD to parse the xml). This is the code that I'm using to try and parse the file: private void refreshForecast() URL url; try { url = new URL( "http://192.168.1.66:8000/google4.xml"); URLConnection connection = url.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection)connection; int responseCode = httpConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { InputStream in = httpConnection.getInputStream(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); // falls over here parsing the xml. Document dom = db.parse(in); } } catch (ManyExceptions e) { .... } A cutdown version of the xml that produces the error is: <?xml version="1.0"?> <xml_api_reply version="1"> <weather> <forecast_information> <city>Hamilton</city> </forecast_information> </weather> </xml_api_reply> The stackt
Tags (comma-separated)
Save Edits
Cancel