Reputation: 1484
I have an RSS feed with the image of the feed encoded like this:
<imageItem src="http://www.example.com/picture.jpg">
<img width="386" height="173" src="http://www.abb-conversations.com/DACH/files/2015/06/Traumpraktikum-755-386x173.jpg" class="attachment-teaser-tablet wp-post-image" alt="Traumpraktikum-755" style="float:left; margin:0 15px 15px 0;"/>
</imageItem>
Using NSXMLParser, I was to be able to extract that src link. Currently the way I'm doing it does not return anything because it is looking for something like <imageItem> xxx.jpg </imageItem>
.
Here is the code:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([self.element isEqualToString:@"title"]) {
[self.title appendString:string];
}
else if ([self.element isEqualToString:@"link"]) {
[self.link appendString:string];
}
else if ([self.element isEqualToString:@"imageItem"]) {
[self.image appendString:string];
}
}
Upvotes: 0
Views: 249
Reputation: 107221
The image url is set as the attribute of that img
element.
You need to implement the following NSXMLParser delegate
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"img"])
{
NSString *urlValue = [attributeDict valueForKey:@"src"];
NSLog(@"%@",urlValue);
}
}
Refer NSXMLParserDelegate for more details
Upvotes: 1
Reputation: 2983
Try this delegate method
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)nameSpaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqual:@"img"])
{
NSLog(@"SRC: %@",[attributeDict objectForKey:@"src"]);
}
}
Upvotes: 1