我正在解析CDATA,但我得到了值...
我想在这两个RSS Feed中http://nikelebron.net/feed/
和http://www.nicekicks.com/feed/
获取 src 值
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
NSString *someString = [[NSString alloc] initWithData:CDATABlock
encoding:NSUTF8StringEncoding];
}
答案 0 :(得分:0)
此代码将打印CDATA中的所有 jpg图像链接,
-(void) parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock{
NSString *cDataString = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
NSDataDetector *detect = [[NSDataDetector alloc] initWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [detect matchesInString:cDataString options:0 range:NSMakeRange(0, [cDataString length])];
for(int i=0; i<matches.count;i++){
NSTextCheckingResult *result = [matches objectAtIndex:i];
NSString *linkUrl = [result URL].absoluteString;
if([[linkUrl pathExtension] isEqualToString:@"jpg"]){
//for your requirement, change the above line to
//NSString *pathExtension = [linkUrl pathExtension];
//if((pathExtension.length>=3)&&([[pathExtension substringToIndex:3] isEqualToString:@"jpg"])){
NSLog(@"image link:%@", linkUrl);
}else NSLog(@"link:%@", linkUrl);
}
}