在我的应用中,我使用XML feed解析器来获取所有内容。但是我得到了解析器中包含的 null图像数组。
我的解析代码如下:
#pragma mark MWFeedParserDelegate
- (void)feedParserDidStart:(MWFeedParser *)parser {
NSLog(@"Started Parsing: %@", parser.url);
}
- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
NSLog(@"Parsed Feed Item: “%@”", item.title);
if (item)
{
[arr_itemIdentifier addObject:item.identifier];
[arr_itemTitle addObject:[item.title gtm_stringByUnescapingFromHTML]];
[arr_itemLink addObject:item.link];
[arr_itemdate addObject:item.date];
if( nil != item.updated )
{
[arr_itemupdated addObject:item.updated];
}
[arr_itemsummery addObject:item.summary];
NSString *renderedSummary = [item.summary stringByReplacingOccurrencesOfRegex:@"<[^>]*?>"
withString:@""];
[arr_itemRenderedSummary addObject:renderedSummary];
if( nil != item.content )
{
[arr_itemContent addObject:item.content];
}
}
NSLog(@"%@",item.description);
NSLog(@"item.enclosurs = %@",item.enclosures); // here i got null array so the for loop is not executed
for( NSDictionary *itemEnclosure in item.enclosures )
{
NSString *mimeType = [itemEnclosure objectForKey:@"type"];
if( [@"video/example" isEqualToString:mimeType] )
{
} else if( [@"image/example" isEqualToString:mimeType] )
{
NSString *itemAnchor = [itemEnclosure objectForKey:@"url"];
NSArray *captures = [itemAnchor arrayOfCaptureComponentsMatchedByRegex:DWFeedHTMLImageElementSrcValueRegex];
if( 0 < captures )
{
[arr_imageURL addObject:[itemEnclosure objectForKey:@"url"]];
}
[arr_thumbImage addObject:[itemEnclosure objectForKey:@"url"]];
//feedItem.thumbnailURL = feedItem.imageURL;
}
}
int k=0;
NSLog(@"arr_itemContent = %@",item.content);
NSLog(@"arr_itemdate = %@",item.date);
NSLog(@"arr_itemIdentifier = %@",item.identifier);
NSLog(@"arr_itemLink = %@",item.link);
NSLog(@"arr_itemRenderedSummary = %@",[arr_itemRenderedSummary objectAtIndex:k]);
NSLog(@"arr_itemsummery = %@",item.summary);
NSLog(@"arr_itemTitle = %@",item.title);
NSLog(@"arr_itemupdated = %@",item.updated);
k++;
}
- (void)viewDidLoad
{
NSURL *feedURL = [NSURL URLWithString:str_url];
feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
feedParser.delegate = self;
feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
feedParser.connectionType = ConnectionTypeAsynchronously;
[feedParser parse];
}
我获得了除图像之外的所有数组信息。我还通过<p><a href="http://wpcore.mpf.s3.amazonaws.com/wp-content/uploads/2012/11/DDD-2121.jpg">
的日志输出获取包含以下内容的图片网址:
item.content
CONTENTS