Ios 雅虎天气预报的XML解析

Ios 雅虎天气预报的XML解析,ios,xml,parsing,weather,Ios,Xml,Parsing,Weather,我正在为iphone制作一个应用程序,希望通过以下xml显示当前温度和天气图像: 我能够解析xml并读取描述选项卡数据。但是我如何进一步解析它以从中获取温度和天气图像呢?温度处于yweather:condition。查看作为didStartElement的attributes返回的NSDictionary 温度的测量单位为y天气:单位(同样在属性字典中) 图像链接包含在说明中。您应该真正使用HTML解析器,如中所述,或者(gasp)您可以使用正则表达式: NSError *error = ni

我正在为iphone制作一个应用程序,希望通过以下xml显示当前温度和天气图像:


我能够解析xml并读取描述选项卡数据。但是我如何进一步解析它以从中获取温度和天气图像呢?

温度处于
yweather:condition
。查看作为
didStartElement
attributes
返回的
NSDictionary

温度的测量单位为
y天气:单位
(同样在
属性
字典中)

图像链接包含在
说明中
。您应该真正使用HTML解析器,如中所述,或者(gasp)您可以使用正则表达式:

NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(<img\\s[\\s\\S]*?src\\s*?=\\s*?['\"](.*?)['\"][\\s\\S]*?>)+?"
                                                                       options:NSRegularExpressionCaseInsensitive
                                                                         error:&error];

NSString *imageUrlString = nil;
NSTextCheckingResult *match = [regex firstMatchInString:htmlString options:0 range:NSMakeRange(0, [htmlString length])];
if (match)
    imageUrlString = [htmlString substringWithRange:[match rangeAtIndex:2]];
NSError*error=nil;
NSRegularExpression*regex=[NSRegularExpression regular expression with pattern:@“()+?”
选项:nsregularexpressioncase不敏感
错误:&错误];
NSString*imageUrlString=nil;
NSTextCheckingResult*match=[regex firstMatchInString:htmlString选项:0范围:NSMakeRange(0[htmlString长度])];
如果(匹配)
imageUrlString=[htmlString substringWithRange:[match RangeAtinex:2]];