如何从 Web 服务器上的 xml 文件读取数据

发布于 2024-10-06 02:42:30 字数 168 浏览 0 评论 0原文

我想从放置在 Web 服务器上的 xml 文件读取数据。然后我想在 UITableView 中显示这些数据。有人可以帮助我如何从文件中读取数据。

另外我需要每 30 秒更新一次数据。所以有人可以告诉我如何每 30 秒读取该 xml 文件。

提前致谢。

问候, 高拉夫·阿罗拉

I want to read data from a xml file placed on a web server. then I want to display this data in a UITableView. Can someone help me how can I read data from a file.

Also I need to update the data in each 30 sec.So can someone tell me how can I read that xml file in every 30 secs.

Thanks in advance.

Regards,
Gaurav Arora

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洒一地阳光 2024-10-13 02:42:31

您可以使用 NSUrlConnection 从服务器获取 XML 文档。我个人认为,使用 NSUrlConnection 的漂亮包装来简化应用程序代码会更方便。

目前我在我的项目中使用 ASIHHTPRequest 和 GTM-HTTP-Fetcher。两个图书馆对我来说都运行得很好。

收到 XML 文档后,您应该创建一个 NSXMLParser 来提取信息。请注意,基于文档的 API 在 iPhone 上不可用。

从服务器收到信息后,您可能会考虑使用 dispatch_after 重新安排一个新的执行块,并延迟 30 秒以激活重新获取。

我建议在后台操作中执行远程服务器访问和 XML 解析,这样不会阻塞主循环管理的 UI 线程。一旦在后台收到新数据,我通常会使用 dispatch_async() 将执行块放入主 (UI) 队列中,该队列处理 UITableView 上的更新>。

You might use NSUrlConnection to fetch the XML document from the server. Personally I think, it is more convenient to use a nice wrapper around NSUrlConnection to simplify your application code.

At the moment I use ASIHHTPRequest and GTM-HTTP-Fetcher in my projects. Both libraries worked quiet well for me.

After receiving the XML document, you should create an NSXMLParser to ingest the information. Please remind that the document based API its not available on the iPhone.

After information has been received from the server, you might think about rescheduling an new execution block using dispatch_after with a delay of 30 seconds to activate refetching.

I recommend to execute the remote server access and XML parsing in an background operation that does not block the UI thread managed by the main loop. As soon as new data has been received in the background, i normally use dispatch_async() to put an execution block onto the main (UI) queue that processes the update on the UITableView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文