6

我正在使用 NSXMLParser 来解析 RSS 提要。早些时候我使用来自 cdata 块的图像 url,但现在我遇到了一个包含图像 url 的提要

<media:content url="http://cdn.example.com/wp-content/uploads/2013/10/article-2462931-18C5CBC000000578-776_634x452.jpg" medium="image"/>

我如何从这个标签中选择图片网址?这是我试图在 didStartElement 方法中使用的,但它不起作用:

if ([elementName isEqual:@"media:content"])
    {
        currentString = [[NSMutableString alloc] init];

        // Basically i need the image url string at this point             

        NSString *imageURLString = [self getFirstImageUrl:currentString];
        imageURL = [NSURL URLWithString:imageURLString];
        [self downloadThumbnails:imageURL];
    }

如何从媒体内容标签中选择图像 url 字符串?谢谢!

4

1 回答 1

9

我没有收到任何答案,但在尝试了不同的事情之后,我能够解决这个问题。我现在正在回答我自己的问题,这样如果有人遇到同样的问题,他们可以解决这个问题,而不会像我一样浪费太多时间。

在 NSXMLParser 的 didStartElement 方法中,我写了以下内容:

if ([elementName isEqual:@"media:content"])
    {
        NSString *imageURLString = [attributeDict objectForKey:@"url"];
        NSLog(@"imgURL %@",imageURLString);

        // Here you can use the imageURLString to download the image
    }
于 2013-10-18T11:10:14.130 回答