从URL读取XML文件 [英] Read XML file from URL
本文介绍了从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
}
您还会发现以下文章非常有用。
- 在Android上使用XML [ ^ ]
- Android发出HTTP请求 [ ^ ]
- Working with XML on Android[^]
- Android making HTTP Requests[^]
You will also find following articles very useful.
检查此链接
如何读取-xml文件和显示 [ ^ ]
这篇关于从URL读取XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文