XML正文:
<description>
<img src="http://static.ibnlive.in.com/ibnlive/pix/slideshow/02-2013/pics-serial-blasts/hyd-blasts-90.jpg" alt="In pics: Serial blasts in Hyderabad kill 14" title="In pics: Serial blasts in Hyderabad kill 14" border="0" width="90" height="62" align="left" hspace="5"/>At least 14 people are feared to have been killed in a series of explosions on Thursday evening which took place in Dilsukh Nagar bus stand area of Hyderabad.
</description>
答案 0 :(得分:4)
利用NSXMLParser
解析XML。然后使用下面的方法从标记
- (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"]);
}
如果您没有使用任何XML Parser并将XML视为简单的String,那么尝试操作字符串
NSString *imgURL= @"<description><img src=\"http://static.ibnlive.in.com/ibnlive/pix/slideshow/02-2013/pics-serial-blasts/hyd-blasts-90.jpg\" alt=\"In pics: Serial blasts in Hyderabad kill 14\" title=\"In pics: Serial blasts in Hyderabad kill 14\" border=\"0\" width=\"90\" height=\"62\" align=\"left\" hspace=\"5\"/>At least 14 people are feared to have been killed in a series of explosions on Thursday evening which took place in Dilsukh Nagar bus stand area of Hyderabad.</description>";
imgURL = [imgURL substringFromIndex:[imgURL rangeOfString:@"src="].location+[@"src=" length]+1];
imgURL = [imgURL substringToIndex:[imgURL rangeOfString:@"alt="].location-2];
NSLog(@"%@",imgURL);