开发者

Parsing Flickr Image-URL with NSXMLParser

开发者 https://www.devze.com 2023-03-10 16:27 出处:网络
I\'ve the following problem: I\'m parsing an XML File from Flickr API http://api.flickr.com/services/feeds/photos_public.gne?tags= with a specific tag, provided by the user before.

I've the following problem:

I'm parsing an XML File from Flickr API http://api.flickr.com/services/feeds/photos_public.gne?tags= with a specific tag, provided by the user before.

Then I get a XML file where in开发者_开发知识库 each <entry> item a line exists like

<link rel="enclosure" type="image/jpeg" href="IMAGEURL">

Is there an easy way to parse this line of code with NSXMLParser? Or should I use another way to get the IMAGEURL?


You should be able to use the delegate method parser:didStartElement:namespaceURI:qualifiedName:attributes: to get that info. The attributes are available in the attributesDict. So you can get the IMAGEURL using,

NSString * imageURLString = [attributesDict objectForKey:@"href"];

when elementName is "link".


I have tried this as well and it doesn't work anymore because the html is not well formed xml. This is the error I got: NSXMLParserErrorDomain Code=111

Now using the Flickr API and it works like a charm. You have to create an API key: https://www.flickr.com/services/apps/create/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号