开发者

do not understand xml parsing code

the following code is for xml parsing.

try
{
HttpEntity entity = response.getEntity();
final InputStream in = entity.getContent();
final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
final XmlHandler handler = new XmlHandler();
Reader reader = new InputStreamReader(in, "UTF-8");
InputSource is = new InputSource(reader);
is.setEncoding("UTF-8");
parser.parse(is, handler);
//TODO: get the data from your handler
}
catch (final Exceptio开发者_运维问答n e)
{
Log.e("ParseError", "Error parsing xml", e);
}

over here where do i pass the url. also the response object in the line

response.getEntity() is an object of HttpResponse()?

thank you in advance.


The code you show is the processing after the url connection has been opened, and the result has been obtained. At this point there is no more url to pass.

response is the HttpResponse.


I think you can do something like this:

Url url = new URL("http:// [and so on]");
XMLReader xmlReader = parser.getXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.parse(new InputSource(url.openStream()));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜