NSXMLParser rss图片网址? [英] NSXMLParser rss Image urls?
本文介绍了NSXMLParser rss图片网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用nsxmlparser解析rss,我想从rss中获取一些图像...我该怎么做?
所以这里是一个rss的例子
< p> ;< img scr =IMGURL>< / p>
我如何获得IMGURL
<谢谢,
TC
解决方案
这是一个快速入侵 - 只有你知道字符串不是这样做要改变立场。否则你可能会崩溃。
//出于演示目的,我们可以说你的< p>< img scr =IMGURL> ;< / p为H.是一个名为sourceString的字符串
//将其切割成这样的数组并从数组中获取位置
//创建数组
NSArray * tempArray = [sourceString componentsSeparatedByString :@\];
//这样做了,它创建了一个源字符串对象数组,用
//分隔,所以在你的tempArray中你会有两个对象
// objectAtIndex 0将是:< p>< img scr =你不需要这个我们可以忽略它
// objectAtIndex 1将是你想要的字符串。它将是:IMGURL
//所以现在你可以快速创建一个字符串,如
NSString * imgURL = [[tempArray objectAtIndex:1] description];
这是一个快速而肮脏的伎俩......但它确实有效!只要数据保持相同的格式。你的电话!
I am parsing rss using nsxmlparser and I would like to get some images from the rss...how can I do that?
so here is an example of the rss
<p><img scr = "IMGURL"></p>
how can I get the "IMGURL"
thanks, TC
解决方案
Here is a quick hack - only do this if you know the strings are not going to change position. Otherwise you risk crashing.
//for demo purposes lets say your <p><img scr = "IMGURL"></p> is a string named sourceString
//chop it up into an array like this and grab it from the arrays position
//create an array
NSArray *tempArray = [sourceString componentsSeparatedByString:@"\""];
//what this has done, it has create an array of objects from your source string separated by "
//so in your tempArray you will have two objects
// objectAtIndex 0 will be: <p><img scr = you wont need this so we can ignore it
// objectAtIndex 1 will be the string you want. it will be: IMGURL
// so now you can quickly create a string from it like this
NSString * imgURL = [[tempArray objectAtIndex:1]description];
Its a quick and dirty trick... but it works! So long as the data stays the same format. Your call!
这篇关于NSXMLParser rss图片网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文