Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:42:01+00:00 2026-06-18T06:42:01+00:00

I am making a mac application, and I need it to parse a local

  • 0

I am making a mac application, and I need it to parse a local xml file and display it into a tableView. For some reason, I get a blank row in my tableView, which makes no sense, as it has found characters that are in my xml. Here is my code:

- (void)parserDidStartDocument:(NSXMLParser *)parser{
    NSLog(@"found file and started parsing");
}

- (void)parseXMLFileAtURL:(NSString *)URL
{
    //you must then convert the path to a proper NSURL or it won't work
    NSURL *xmlURL = [NSURL URLWithString:URL];

    // here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error
    // this may be necessary only for the toolchain

    rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];


    // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
    [rssParser setDelegate: self];
    // Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
    [rssParser setShouldProcessNamespaces:NO];
    [rssParser setShouldReportNamespacePrefixes:NO];
    [rssParser setShouldResolveExternalEntities:NO];
    [rssParser parse];
}

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
    NSString * errorString = [NSString stringWithFormat:@"Unable to download XML feed (Error code %i )", [parseError code]];
    NSLog(@"Error parsing XML: %@", errorString);
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    //NSLog(@"found this element: %@", elementName);
    currentElement = [elementName copy];

    if ([elementName isEqualToString:@"event"]) {
        // clear out our story item caches...
        item = [[NSMutableDictionary alloc] init];
        date = [[NSMutableString alloc] init];
        opponent = [[NSMutableString alloc] init];
        location = [[NSMutableString alloc] init];
        time = [[NSMutableString alloc] init];
        games = [[NSMutableString alloc] init];

    }

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    NSLog(@"ended element: %@", elementName);

    if ([elementName isEqualToString:@"event"]) {
        // save values to an item, then store that item into the array...
        [item setObject:date forKey:@"date"];
        [item setObject:opponent forKey:@"opponent"];
        [item setObject:location forKey:@"location"];
        [item setObject:time forKey:@"time"];
        [item setObject:games forKey:@"games"];
        NSMutableArray *stories = [[NSMutableArray alloc] init];
        [stories addObject:[item copy]];

        [arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                                    date, @"date", 
                                    opponent, @"opponent",
                                    location, @"location",
                                    time, @"time",
                                    games, @"games"
                                    , nil]];

    }

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    //NSLog(@"found characters: %@", string);
    // save the characters for the current item...

    if ([date isEqualToString:@"date"]) {
        [date appendString:string];
    } else if ([opponent isEqualToString:@"opponent"]) {
        [opponent appendString:string];
    } else if ([location isEqualToString:@"location"]) {
        [location appendString:string];
    } else if ([time isEqualToString:@"time"]) {
        [time appendString:string];
    } else if ([games isEqualToString:@"games"]) {
        [games appendString:string];
    }
}

- (void)parserDidEndDocument:(NSXMLParser *)parser {
    NSLog(@"all done!");
    [tabelview reloadData];
}

When i remove my adding part, where it adds item to the arraycontroller, and add

[arrayController addObject:stories]; I get a buch of ('s

If there is anything else you need, do not just down-vote, and instead tell me. Thanks!

Here is my xml:

    <?xml version="1.0" encoding="ISO-8859-1"?>
<xmlData>
    <event>
        <date>date here</date>
        <opponent>opponent here</opponent>
        <location>location here</location>
        <time>time here</time>
        <games>games here</games>
    </event>
    <event>
        <date>date here</date>
        <opponent>opponent here</opponent>
        <location>location here</location>
        <time>time here</time>
        <games>games here</games>
    </event>
    <event>
        <date>date here</date>
        <opponent>opponent here</opponent>
        <location>location here</location>
        <time>time here</time>
        <games>games here</games>
    </event>
    <event>
        <date>date here</date>
        <opponent>opponent here</opponent>
        <location>location here</location>
        <time>time here</time>
        <games>games here</games>
    </event>
</xmlData>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:42:02+00:00Added an answer on June 18, 2026 at 6:42 am

    The error is in your parser. Please revise the logic. You are not using your object item when filling your table view array. Also, you are not catching the text in between the XML elements and are not assigning them to the appropriate variables.

    Note the following:

    • When you enter an element, keep track of which element you are in currently
    • When you find characters you have to fill the appropriate attribute variable according to which element you are in
    • When you finish the event element, you should add your item with all its filled in keys into your data array.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a new Mac OS X application. (not an iPhone app) This is
I am making a Java application that is stored in a .jar file and
I'm making an app where I need to copy certain file from the app
I'm porting Chicken of VNC Mac application into iphone application I am having source
I am making an application on Mac and I want to be able to
I am making an AppleScript application with AppleScript 2.2 on Mac OS X 10.7
I'm making a Mac OS X application that runs on Snow Leopard and later.
How to get the modify Shift key in cocoa. I am making an application
I am making my first Mac OS X application and I'm stuck with a
I have a .NET application that I need to launch into its own process

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.