Ankit Sachan
Ankit Sachan

Reputation: 7850

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 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

Upvotes: 0

Views: 1355

Answers (1)

Vladimir
Vladimir

Reputation: 170849

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"]];
   }
...
}

Upvotes: 2

Related Questions