How can I check the content of the arrays? Parsing XML file with ObjectiveC

Posted by skiria on Stack Overflow See other posts from Stack Overflow or by skiria
Published on 2010-05-07T13:55:09Z Indexed on 2010/05/07 13:58 UTC
Read the original article Hit count: 252

I have 3 classes-> video { nameVideo, id, description, user... } topic {nameTopic, topicID, NSMutableArray videos; } category {nameCategory, categoryID, NSMUtableArray topics}

And then in my app delegate I defined-> NSMutableArray categories;

I parse an XML file with this code. I try the arrays hierachy, and i think that i don't add any object on the arrays. How can I check it? What's wrong?

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

    if([elementName isEqualToString:@"Videos"]) { //Initialize the array. appDelegate.categories = [[NSMutableArray alloc] init]; }

    else if ([elementName isEqualToString:@"Category"]) { aCategory = [[Category alloc] init];

    aCategory.categoryID = [[attributeDict objectForKey:@"id"] integerValue];
    
    
    NSLog(@"Reading id category value: %i", aCategory.categoryID);
    

    }

    else if ([elementName isEqualToString:@"Topic"]) { aTopic = [[Topic alloc] init];

    aTopic.topicID = [[attributeDict objectForKey:@"id"] integerValue];
    
    
    NSLog(@"Reading id topic value: %i", aTopic.topicID);
    

    }

    else if ([elementName isEqualToString:@"video"]) {

    aVideo = [[Video alloc] init];
    
    
    aVideo.videoID = [[attributeDict objectForKey:@"id"] integerValue];
    aVideo.nameTopic = currentNameTopic; 
    aVideo.nameCategory = currentNameCategory; 
    
    
    NSLog(@"Reading id video value: %i", aVideo.videoID);
    

    }

    NSLog(@"Processing Element: %@", elementName); }

  • (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

    if(!currentElementValue) currentElementValue = [[NSMutableString alloc] initWithString:string]; else [currentElementValue appendString:string];

    NSLog(@"Processing Value: %@", currentElementValue);

}

  • (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

    if([elementName isEqualToString:@"Videos"]) return;

    if ([elementName isEqualToString:@"Category"]) { [appDelegate.categories addObject:aCategory]; [aCategory release]; aCategory = nil; }

    if ([elementName isEqualToString:@"Topic"]) { [aCategory.topics addObject:aTopic]; //NSLog(@"contador: %i", [aCategory.topics count]); //NSLog(@"contador: %@", aTopic.nameTopic);

    [aTopic release];
    aTopic = nil;
    

    }

    if ([elementName isEqualToString:@"video"]) { [aTopic.videos addObject:aVideo]; NSLog(@"count number videos: %i", [aTopic.videos count]); --> always 0 NSLog(@"NOM CATEGORIA VIDEO: %@", aVideo.urlVideo); --> OK

    [aVideo release];
    aVideo = nil;
    

    }

    if ([elementName isEqualToString:@"nameCategory"]) { //[aCategory setValue:currentElementValue forKey:elementName]; aCategory.nameCategory = currentElementValue; currentNameCategory = currentElementValue; }

    if ([elementName isEqualToString:@"nameTopic"]) { aTopic.nameTopic = currentElementValue; currentNameTopic = currentElementValue; }

    else [aVideo setValue:currentElementValue forKey:elementName];

    [currentElementValue release]; currentElementValue = nil;

}

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa-touch