How can I fix a unexpected End of Document Exception
I saw the other posts on this site and others but people have solved this different ways and none of them required an authentication to access the XML.
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("some web site");
httpGet.addHeader("Authorization", getAuthHeader());
HttpResponse response = httpclient.execute(httpGet);
Document开发者_运维技巧BuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(response.getEntity().getContent());
NodeList nodelst = doc.getElementsByTagName("ad");
I know that my HTTP request is fine; its status is 200, but I get this
saxParserException: unexpected end of document
at the line that I have spaced out. Does anyone know how to start from the begining or am I getting a blank file... how can I test for that?
Thanks for your help
the XML looks like this. it is pretty simple
<ads>
<ad>
<id>6</id>
<minViews>10</minViews>
<duration>4</duration>
<actionUrl>
some url
</actionUrl>
<imageUrl>
some url
</imageUrl>
<impressionCount>0</impressionCount>
</ad>
</ads>
Status 200 doesn't have anything to do with the content of the message. There is probably an error in your xml. What does your xml look like?
http://pronto.mersoft.com/pronto/adclick?appKey=sS5fPOH8QSGl0ExQet-pwg&deviceId=12345&adId=6
...
http://pronto.mersoft.com/pronto/image?id=6&appKey=sS5fPOH8QSGl0ExQet-pwg
I believe that the ampersands (&
) in those lines need to be escaped (as &
) for this to be legal XML.
精彩评论