The simplest thing is to do something like this:
NSXMLParser *xmlParser = [[NSXMLParser alloc]initWithData:<yourNSData>]; [xmlParser setDelegate:self]; [xmlParser parse];
Note that setDelegate: sets the delegate to "self", which means the current object. So, in this object you need to implement the delegate methods that you mentioned in the question.
so on in your code, insert:
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{ NSLog(@"I just found a start tag for %@",elementName); if ([elementName isEqualToString:@"employee"]){
etc .. and others.
This is a bit more complicated if you want to do something like setting a variable to the value of a tag, but this is usually done using a caleld class variable, for example, " BOOL inEmployeeTag
", which you set to true (YES) in the didStartElement
: method and false in the didEndElement
: method - and then check its value in the foundCharacters
method. If so, then you assign var to the value of the string, and if not, then no.
Richard
richard
source share