【发布时间】:2016-11-08 22:14:02
【问题描述】:
我有一个显示 XML 提要结果的集合视图。它工作得很好,但我需要在本地保存 XML 提要的结果(例如,如果没有可用的互联网连接)。
我知道如何在本地保存原始提要,但我认为我真正需要做的是遍历 XML 提要中的项目并将每个项目保存为 NSData 项目。
这是正确的思考方式,还是您有任何有用的建议或提示?
- (void)startParsing
{
NSXMLParser *xmlparser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://images.apple.com/main/rss/hotnews/hotnews.rss#sthash.TyhRD7Zy.dpuf"]];
[xmlparser setDelegate:self];
[xmlparser parse];
if (_marrXMLDataCollection.count != 0) {
// Save XML to NSData items in background?
[self.collectionView reloadData];
}
}
这是提要的示例,我也将其存储在 Documents 目录中,名称为 localdata.plist:
(
{
link = "\nhttp://www.apple.com/pr/library/2016/04/26Apple-Reports-Second-Quarter-Results.html?sr=hotnews.rss";
pubDate = "\nTue, 26 Apr 2016 14:44:21 PDT";
title = "\nApple Reports Second Quarter Results";
},
{
link = "\nhttp://www.apple.com/final-cut-pro/in-action/trim-editing/?sr=hotnews.rss";
pubDate = "\nWed, 20 Apr 2016 10:05:59 PDT";
title = "\n\nFinal Cut Pro X helps small company delight world\U2019s biggest clients";
},
{
link = "\nhttp://www.apple.com/ipad-pro/?sr=hotnews.rss";
pubDate = "\nMon, 21 Mar 2016 12:00:03 PDT";
title = "\n\nApple Introduces 9.7-inch iPad Pro";
},
{
link = "\nhttp://www.apple.com/iphone-se/?sr=hotnews.rss";
pubDate = "\nMon, 21 Mar 2016 11:58:09 PDT";
title = "\n\nApple Introduces iPhone SE \U2014 the Most Powerful Phone with a 4-inch Display";
},
【问题讨论】:
-
为什么不直接保存 XML?
-
@Wain 您是说将 XML 保存在属性列表中,还是其他的?在那种情况下,我不确定它的效果如何,因为最终在提要中也会有照片,我需要将它们转换为 NSData 项目,而不是/另外,对吗?
-
照片在 XML 中的格式如何? base64 编码的字符串?
-
@Wain 是的,照片将采用 base64 编码
标签: ios objective-c xml nsxmlparser