views:

255

answers:

2

Hello,

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

A: 

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"]];
   }
...
}
Vladimir
THANX ALOT........
Ankit Sachan
What did you mentioned in the "parser did end element " and "found characters method"
Warrior
@Warrior - you do not need them to get data from attribute
Vladimir
@vladimir- what i should do if enlosure tag is a child of another tag like <medi:group><enclosure url="http://www.abc.com/wp-content/uploads/2010/01/abc.jpg" length="64690" type="image/jpg" /></media group>.Then how could i retrieve its contents..please check my recent post...
Warrior
@vladimir-- i got the answer for the question. thanks
Warrior
A: 

Warrior, can you send me the answer? Thanks. [email protected]

Isra
url will automatically be parsed just while XML parsing put the logic accordingly to parse the url.
Ankit Sachan