Search code examples
iphoneobjective-cnsxmlparsernsxml

NSXML Parsing through objective C


I am working on xml parsing through Objective C. I am getting trouble into following part. Please help me out. I am using NSXMLParser class and its delegates.

How to trace out "url", "type", "height" these tags from below XML code.

<image url="http://d.img.com/a/r/rids/20110203/i/r32323.jpg?
x=130&amp;y=91&amp;q=85&amp;sig=bJdeYbrqFsYUuZJ.fFwa8g--"  
type="image/jpeg"  height="91" width="130"/>

Solution

  • Implement delegate function

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
    

    and inside it

    NSLog(@"url: %@", [attributeDict valueForKey:@"url"]);
    

    etc.