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

  • SEARCH
  • Home
  • 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 594839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:59:47+00:00 2026-05-13T15:59:47+00:00

Im trying to parse XML (which seems ok) and populate a Table View on

  • 0

Im trying to parse XML (which seems ok) and populate a Table View on Iphone. I’m working from apples siesmec examples.
My XML looks something like this and has about 10 entries going from artist1 to artist10

<promo>
<id>
42
</id>
<artistname>
artist1
</artistname>
<img>
http://address.com/avatar_42.jpg
</img>
</promo>

If I put in breakpoints I can see all of the correct names but when the parsing is finished all 10 cells in my table say “artist10:

The Code for the xml is in the file as the table view controller. Can you see anything thats glaring a stupid mistake?

#pragma mark Parser constants
    // Limit the number of parsed earthquakes to 50.

static const const NSUInteger kMaximumNumberOfEarthquakesToParse = 50;

static NSUInteger const kSizeOfEarthquakeBatch = 10;

// Reduce potential parsing errors by using string constants declared in a single place.
static NSString * const kArtistName = @"artistname";
static NSString * const kEntryElementName = @"promo";
static NSString *const kEntryElementID =@"id";
static NSString *const kEntryElementImg=@"img";


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
    if (parsedPromoListCounter >= kMaximumNumberOfEarthquakesToParse) {
        // Use the flag 
  didAbortParsing = YES;
        [parser abortParsing];
    }
    if ([elementName isEqualToString:kEntryElementName]) {
        PromoListItem *promoitem = [[PromoListItem alloc] init];
        self.currentPromoListObject = promoitem;
        [promoitem release];

} else if ([elementName isEqualToString:kEntryElementImg]) {
  //nothing for now
    } else if ([elementName isEqualToString:kArtistName] || [elementName isEqualToString:kEntryElementImg] || [elementName isEqualToString:kEntryElementID]) {
  accumulatingParsedCharacterData = YES;

        // The mutable string needs to be reset to empty.
        [currentParsedCharacterData setString:@""];
    }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {     
 if ([elementName isEqualToString:kEntryElementName]) {
  [self.currentParseBatch addObject:self.currentPromoListObject];
  parsedPromoListCounter++;
  if (parsedPromoListCounter % kSizeOfEarthquakeBatch == 0) {
   [self performSelectorOnMainThread:@selector(addPromosToList:) withObject:self.currentParseBatch waitUntilDone:NO];
   self.currentParseBatch = [NSMutableArray array];
  }
 } else if ([elementName isEqualToString:kArtistName]) {
  self.currentPromoListObject.artistName=self.currentParsedCharacterData;
 } else if ([elementName isEqualToString: kEntryElementID]) {
  self.currentPromoListObject.artistID = self.currentParsedCharacterData;
 } else if ([elementName isEqualToString:kEntryElementImg]) {

  self.currentPromoListObject.imgLink=self.currentParsedCharacterData;
 }
 // Stop accumulating parsed character data. We won't start again until specific elements begin.
 accumulatingParsedCharacterData = NO;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
   if (accumulatingParsedCharacterData) {
    // If the current element is one whose content we care about, append 'string'
    // to the property that holds the content of the current element.
    [self.currentParsedCharacterData appendString:string];
   }
  }`

And this is how I populate my table view

#pragma mark Table View Methods

// The number of rows is equal to the number of earthquakes in the array.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.promoList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

 // Each subview in the cell will be identified by a unique tag.
    static NSUInteger const kartistNameLabelTag = 2;

    // Declare references to the subviews which will display the earthquake data.
    UILabel *artistNameLabel = nil;


 static NSString *kpromoCellID = @"promoCellID";   

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kpromoCellID];
 if (cell == nil) {
        // No reusable cell was available, so we create a new cell and configure its subviews.
  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kpromoCellID] autorelease];

        artistNameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, 190, 20)] autorelease];
  artistNameLabel.tag = kartistNameLabelTag;
        artistNameLabel.font = [UIFont boldSystemFontOfSize:14];
        [cell.contentView addSubview: artistNameLabel];

 } else {
        // A reusable cell was available, so we just need to get a reference to the subviews using their tags.
        artistNameLabel = (UILabel *)[cell.contentView viewWithTag:kartistNameLabelTag];

    }

    // Get the specific promo for this row.
 PromoListItem *promo = [promoList objectAtIndex:indexPath.row];

    // Set the relevant data for each subview in the cell.
    artistNameLabel.text =promo.artistName;

 return cell;

} 
  • 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-05-13T15:59:48+00:00Added an answer on May 13, 2026 at 3:59 pm

    This was driving me mad so I went for a different approach.

    Here is the code implementation I did

    I’m not sure which approach is better. Maybe somebody would have an opinion on this?

    The first version that I couldn’t get working seemed to give you more control over what character data gets parsed. That’s the only real benefit that I can see.

     (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
    
        if([elementName isEqualToString:@"promolist"]) {
            //Initialize the array.
            promoList = [[NSMutableArray alloc] init];
        }
        else if([elementName isEqualToString:kEntryElementName]) {
    
            //Initialize the book.
            //aBook = [[Book alloc] init];
            //aBook =[[PromoListItem alloc] init];
            PromoListItem *promo = [[PromoListItem alloc] init];
            self.currentPromoListObject = promo;
            [promo release];
    
        }
    
        NSLog(@"Processing Element: %@", elementName);
    }
    
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    
        if(!currentParsedCharacterData)
            currentParsedCharacterData = [[NSMutableString alloc] initWithString:string];
        else
            [currentParsedCharacterData appendString:string];
    
    NSLog(@"Processing Value: %@", currentParsedCharacterData);   }
    
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
      namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    
        if([elementName isEqualToString:@"promolist"])
        {
            [self.tableView reloadData];
            return;
        }
    
        //There is nothing to do if we encounter the promo element here.
        //If we encounter the promo element howevere, we want to add the book object to the array
        // and release the object.
        else if([elementName isEqualToString:kEntryElementName]) {
            [promoList addObject:currentPromoListObject];
    
            [currentPromoListObject release];
            currentPromoListObject = nil;
        }
        else{
            [currentPromoListObject setValue:currentParsedCharacterData forKey:elementName];
    
            }
        [currentParsedCharacterData release];
        currentParsedCharacterData = nil;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to Parse a local xml file (which has database table
I am trying to parse specific XML file which is located in sub directories
So I'm trying to parse some XML, the creation of which is not under
I am trying to parse XML with jsoup, but I can't find any examples
I'm trying to parse an XML coming from an php request URI: http://caracasfutbolclub.com/service/news.php .
I'm working in an iOS application which uses libXML2 to read XML retrieved from
I am trying to parse XML messages which are send to my C# application
I am trying to use xml.etree.ElementTree to parse responses from eBay finding API, findItemsByProduct.
I'm trying to parse an XML document that has an attribute called link which
I'm trying to parse xml from SharePoint service (lists) using jquery. I have XMLHttpRequest

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.