从URL读取XML文件 [英] Read XML file from URL

查看:285
本文介绍了从URL读取XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想从URL读取XML文件,并从该XML文件中检索数据并在Android应用程序中查看。有没有办法像这样访问。如果你知道的话,请帮帮我。

Hi,
I want to read XML file from URL and retrieve data from that XML file and view in android apps. Is there any way to access like that. Please help me if you know means.

推荐答案

你好,



下面是一个小代码片段演示如何在Android上完成。
Hello,

Below is a small code snippet demonstrating how it can be done on android.
HttpGet uri = null;
Document doc = null;
StatusLine status = null;
HttpResponse resp = null;
DocumentBuilder builder = null;
DefaultHttpClient client = null;
DocumentBuilderFactory factory = null;

uri = new HttpGet("YOUR XML FILE URL GOES HERE");

client = new DefaultHttpClient();
resp = client.execute(uri);
status = resp.getStatusLine();
if (status.getStatusCode() == "200") {
    factory = DocumentBuilderFactory.newInstance();
    builder = factory.newDocumentBuilder();
    doc = builder.parse(resp.getEntity().getContent());
    ...
    // Your code for reading XML doc 
}



您还会发现以下文章非常有用。

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆