Advertisement
Guest User

Untitled

a guest
Oct 18th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "XMLParser.h"
  2.  
  3. @implementation XMLParser
  4. @synthesize thePresentation,theSlide,presentations;
  5. -(id)initXMLParser{
  6.     if(self == [super init]) {
  7.         app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
  8.     }
  9.     return self;    
  10. }
  11.  
  12. -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
  13.    
  14.  
  15.     if ([elementName isEqualToString:@"presentation"]) {
  16.         NSLog(@"user element found – create a new instance of User class...");
  17.         app.presentationArray = [[NSMutableArray alloc] init];
  18.         thePresentation = [[Presentation alloc] init];
  19.         thePresentation.pIdentifier = [attributeDict objectForKey:@"identifier"];
  20.         thePresentation.pLabel = [attributeDict objectForKey:@"label"];
  21.      
  22.         NSLog(@"PLabel: %@", thePresentation.pLabel);
  23.         NSLog(@"PNAME: %@", thePresentation.pIdentifier);
  24.        
  25.     }else if ([elementName isEqualToString:@"slides"]) {
  26.         NSLog(@"Slides");
  27.        
  28.         thePresentation.slides = [NSMutableArray array];
  29.     }else if ([elementName isEqualToString:@"slide"]) {
  30.         NSLog(@"slide");
  31.        
  32.         theSlide = [[Slide alloc] init];
  33.         theSlide.index = [[attributeDict objectForKey:@"index"] integerValue];
  34.         NSLog(@"index :%i", theSlide.index);
  35.         theSlide.sLabel = [attributeDict objectForKey:@"label"];
  36.         NSLog(@"sLabel: %@", theSlide.sLabel);
  37.         theSlide.identifier = [attributeDict objectForKey:@"identifier"];
  38.         NSLog(@"identifier: %@", theSlide.identifier);
  39.        
  40.         [thePresentation.slides addObject:theSlide];
  41.         NSLog(@"thePresentation is: %@", thePresentation.slides);
  42.         NSLog(@"theSlide is: %@", theSlide);
  43.        
  44.     }
  45. }
  46.  
  47.  
  48. -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
  49.    
  50.     if(!currentElementValue){
  51.         currentElementValue = [[NSMutableString alloc] initWithString:string];
  52.     }else
  53.         [currentElementValue appendString:string];
  54.    
  55.     NSLog(@"Processing Value: %@", currentElementValue);
  56. }
  57.    
  58.  
  59.  
  60.  
  61. -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
  62.     if([elementName isEqualToString:@"presentation"]){
  63.         [app.presentationArray addObject:thePresentation];
  64.         thePresentation = nil;
  65.     }
  66. }
  67.  
  68.  
  69. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement