I am trying to parse an XML file with TBXML and put the values into a multidimensional NSMutableArray
but the problem is that the values don't get added into the array, if I output the values then it returns null and 0.
This is my code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self downloadAndParseXml:@"http://www.w3schools.com/XML/note.xml"];
    // RETURNS 0
    NSLog(@"weatherArray count: %d", [weatherArray count]);
    // RETURNS NULL
    NSLog(@"weatherArray value: %@", weatherArray[0][0]);
}
- (void)downloadAndParseXml:(NSString *)xmlUrl
{
    // Allocating the array
    weatherArray = [NSMutableArray array];
    TBXMLSuccessBlock sBlock = ^(TBXML *tbxmlDocument) {
        if (tbxmlDocument.rootXMLElement)
            [self fillArrayWithXmlContents:tbxmlDocument.rootXMLElement];
    };
    TBXMLFailureBlock fBlock = ^(TBXML *tbxmlDocument, NSError *error) {
        NSLog(@"Failureblock: %@\n%@", [error localizedDescription], [error userInfo]);
    };
    [TBXML newTBXMLWithURL:[NSURL URLWithString:xmlUrl] success:sBlock failure:fBlock];
}
- (void)fillArrayWithXmlContents:(TBXMLElement *)element {
    do {
        if (element->firstChild)
            [self fillArrayWithXmlContents:element->firstChild];
        if ([[TBXML elementName:element] isEqualToString:@"note"]) {
            // Adding values into the multidimensional array
            [weatherArray addObject:[NSArray arrayWithObjects:
                [TBXML textForElement:[TBXML childElementNamed:@"to" parentElement:element]],
                [TBXML textForElement:[TBXML childElementNamed:@"from" parentElement:element]],
                [TBXML textForElement:[TBXML childElementNamed:@"heading" parentElement:element]],
                [TBXML textForElement:[TBXML childElementNamed:@"body" parentElement:element]], NULL]];
            // Correct value is getting logged
            NSLog(@"weatherArray value: %@", weatherArray[0][0]);
        }
    } while ((element = element->nextSibling));
}
 
     
    