iosobjective-cxmlparsingtbxml

Make sure data is coming from XML sheet using TBXML parser


Longtime stackoverflow user,first time asker. I am newer to iOS development. I am working on a project where I need to bring in the data from an XML sheet, for this I have chosen the TBXML parser to use.

My problem resides in bringing the data into my app and printing it in the console to make sure I have brought correct information in. I believe I have done all the right steps and my code is fine but I know I am right there,just can't get over the hump of bringing the data in my app

The following is my code in my application, any help that can be provided will be greatly appreciated:

{
    NSURL * sourceXMLUrl = [NSURL URLWithString:@"http://travel.state.gov/_res/rss/TAs.xml"];
    NSData * XMLData = [NSData dataWithContentsOfURL:sourceXMLUrl];

    TBXML * sourceXML = [[TBXML alloc] initWithXMLData:XMLData error:nil];
    NSLog(@"TBXML:%@",sourceXML);
    TBXMLElement * rootElement = sourceXML.rootXMLElement;
    NSLog(@"ROOT:%@",rootElement) 

    TBXMLElement * channelElement = [TBXML childElementNamed:@"channel" parentElement:rootElement];
    TBXMLElement * descriptionElement = [TBXML childElementNamed:@"description" parentElement:channelElement];
    TBXMLElement * itemElement = [TBXML childElementNamed:@"item" parentElement:channelElement];
    TBXMLElement * titleElement = [TBXML childElementNamed:@"title" parentElement:channelElement];
    TBXMLElement * publishDate = [TBXML childElementNamed:@"pubdate" parentElement:channelElement];



    NSMutableDictionary * elementDictionary = [[NSMutableDictionary alloc] init];



       NSString * descriptionText = [TBXML textForElement:descriptionElement];
       NSString * itemText = [TBXML textForElement:itemElement];
       NSString * titleText = [TBXML textForElement:titleElement];
       NSString * publishText = [TBXML textForElement:publishDate];

       NSArray * array = [[NSArray alloc] initWithObjects:descriptionText,itemText,titleText,publishText,nil];

       [elementDictionary setObject:array forKey:descriptionText];

    NSLog(@"description: %@", descriptionText);
    NSLog(@"item text: %@", itemText);
    NSLog(@"title text: %@", titleText);
    NSLog(@"publish text: %@", publishText);









}

Solution

  • If none of your NSLog's are working, check and see whether you've called the method they are within.