NSXMLParser on iOS, how do I use it given a xml file

The simplest thing is to do something like this: NSXMLParser *xmlParser = [[NSXMLParser alloc]initWithData:<yourNSData>]; [xmlParser setDelegate:self]; [xmlParser parse]; Notice that setDelegate: is setting the delegate to ‘self’, meaning the current object. So, in that object you need to implement the delegate methods you mention in the question. so further down in your code, paste in: … Read more

Xml parsing in iOS tutorial [closed]

You can parse XML with below code. But you must need to create classes which you can find below. NSURL *URL = [[NSURL alloc] initWithString:@”http:/sites.google.com/site/iphonesdktutorials/xml/Books.xml”]; NSString *xmlString = [[NSString alloc] initWithContentsOfURL:URL encoding:NSUTF8StringEncoding error:NULL]; NSLog(@”string: %@”, xmlString); NSDictionary *xmlDoc = [NSDictionary dictionaryWithXMLString:xmlString]; NSLog(@”dictionary: %@”, xmlDoc); You need to create this classes for XML parsing with name … Read more

NSXMLParser example

– (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ currentKey = nil; [currentStringValue release]; currentStringValue = nil; if([elementName isEqualToString:@”Value”]){ //alloc some object to parse value into } else if([elementName isEqualToString:@”Signature”]){ currentKey = @”Signature”; return; } } – (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ if(currentKey){ if(!currentStringValue){ currentStringValue = [[NSMutableString alloc] initWithCapacity:200]; } [currentStringValue appendString:string]; } } … Read more