在 iPhone 上保存/解析 XML 的最佳方式
这是我的第一个问题,所以我会尽力遵守问题指南。
我正在开发一个 iPhone 应用程序,用于解析 XML feed 并将其显示在表格中。解析不是问题,但我不确定在应用程序首次运行后优化加载时间的最佳方法。
以下是我正在考虑的不同方法:
每次加载应用程序时解析 XML 提要。 简单的方法,但每次运行应用程序的加载时间可能会更长。
获取提要并将其存储在本地(作为 .xml),然后在本地进行解析。然后,每次打开应用程序时,进行 http 调用以查看 feed 是否已更改。如果没有,就本地解析。如果是这样,请下载新的 feed 并在本地进行解析。 初始加载时间会更长,但在以后的运行中可能会缩短(如果提要未更新)。如果用户信号不好但需要查看数据,此选项将很有用。
解析提要并将其存储到本地 sqlite 数据库中。然后,每次打开应用程序时,进行 http 调用以查看提要是否已更改。如果是这样,请检测已添加/删除哪些对象并相应地更改本地数据库。如果没有,则从本地数据库加载数据。 这可能是最好的选择,但我不确定找到更改需要多长时间。
我的 feed 只有大约 100 个左右的项目,每个项目大约有 20 个字段。
初始解析时间:
- 满条时大约 4-5 秒。
- 大约 5-7 秒,3 个小节。
任何有关哪种选项最有效的见解将不胜感激。
This is my first question so I will do my best to conform to the question guidelines.
I am developing an iPhone app that parses and XML feed to be displayed in a table. Parsing is not a problem but I am not sure of the best way to optimize loading times after initial run of the app.
Here is the different approaches that I am considering:
Parse the XML feed each time the application is loaded. Easy way but possibly longer loading time each run of the app.
Grab the feed and store it locally (as .xml) then parse locally. Then, each time the app is opened, make an http call to see if the feed has been changed. If not, parse locally. If so, download the new feed and parse locally. The initial loading time will be longer but could be cut down on later runs (if the feed as not been updated). This option will be beneficial if the user has a bad signal but needs to see the data.
Parse the feed and store it into a local sqlite db. Then, each time the app is opened, make an http call the see if the feed has been changed. If so, detect which objects have been added/removed and alter local db accordingly. If not, load data from local db. This might be the best option but I am not sure how long finding the changes will take.
My feed is only about 100 or so items, each with roughly 20 fields.
Initial parsing time:
- Roughly 4-5sec with full bars.
- Roughly 5-7sec with 3 bars.
Any insight as to which option would work best would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 xml 数据更改的频率应该是一个因素。如果它每天/每周只改变一次?我会加载它、保存它并检查更新。如果存在更新,则下载新的并覆盖旧的。
I think the frequency of the xml data changing should be a factor. If its only going to change once a day/week? Id load it, save it, and check for updates. If update exists download new and overwrite old.
第三种解决方案显然是最好的,它将允许您的应用程序离线工作并快速启动。要检测更改,您只需将 xml 文件的 MD5 存储在数据库中,并将其与新 XML 文件的 MD5 进行匹配即可。如果数据发生了变化,则只需丢弃所有以前的数据即可。
Third solution is clearly the best and it will allow your app to work offline and start quickly. To detect the change, you can simply store a MD5 of the xml file in database and match it against the MD5 of the new XML file. If data has changed, then simply discard all previous data.