2013-05-03 137 views
-1

我解析CDATA,但我gettings價值......在此 http://nikelebron.net/feed/http://www.nicekicks.com/feed/都RSS提要我希望得到SRC值標籤CDATA解析值

- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock 
{ 
NSString *someString = [[NSString alloc] initWithData:CDATABlock 
              encoding:NSUTF8StringEncoding]; 
} 
+0

也許我的問題需要檢測調整,但我不能告訴你問這裏。 – Caleb 2013-05-03 04:41:52

回答

0

此代碼將打印所有JPG圖像中的CDATA鏈接

-(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); 

    } 
} 
+0

非常感謝你... – bati 2013-05-03 05:06:44

+0

其工作.... – bati 2013-05-03 05:07:06

+0

它不適用於此鏈接「http://www.nicekicks.com/feed/」 – bati 2013-05-03 05:13:29