unable to extract image url in xml parsing in iphone
I am quite new to the iphone development, I am using xml parsing to parse contents of a feed
this feed contains this line
<enclosure url="http://www.abc.com/wp-content/uploads/2010/01/abc.jpg" length="64690" type="image/jpg" />
no I want to extract http://www.abc.com/wp-content/uploads/2010/01/abc.jpg
XML开发者_JAVA百科 structure is like this
<item>
<title>ABC</title>
<description>asgafgfafdasf</description>
<enclosure url="http://www.abc.com/wp-content/uploads/2010/01/abc.jpg" length="64690" type="image/jpg" />
</item>
I got values corresponding to description and tile
but unable to put down logic to parse that image url
CAn any bosy shed some light on this.
Thanx in advance
url value (as well as length and type) is element's attribute. If you use NSXMLParser then in delegate's didStartElement method you can get it using: (you may also want to check if data is valid while retrieving it)
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
...
if ([elementName equalsToString:@"enclosure"]){
NSString* myUrl = [NSString stringWithString:[attributeDict objectForKey:@"url"]];
}
...
}
精彩评论