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 9121859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:57:29+00:00 2026-06-17T05:57:29+00:00

Im searching to parse all the attributes unit1 and unit2 from the N tags

  • 0

Im searching to parse all the attributes “unit1” and “unit2” from the N tags of this simplified xml file, and then put them in a UITableView:

<xml>
<meta></meta>
<time1>
<product>
<value1 id="id1Time1" unit1="unit1Time1" number1="number1Time1"/>
<value2 id="id2Time1" unit2="unit2Time1" number2="number2Time1"/>
</product>
</time1>
<time2>
<product>
<value1 id="id1Time2" unit1="unit1Time2" number1="number1Time2"/>
<value2 id="id2Time2" unit2="unit2Time2" number2="number2Time2"/>
</product>
</time2>
...
<timeN>
<product>
<value1 id="id1TimeN" unit1="unit1TimeN" number1="number1TimeN"/>
<value2 id="id2TimeN" unit2="unit2TimeN" number2="number2TimeN"/>
</product>
</timeN>
</xml>

I’m using NSXMLParser, self delegate, and I’m using this code:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    currentElement = [elementName copy];
    if ([elementName isEqualToString:@"value1"]) {
        arrayUnit1 = [[NSMutableArray alloc] init]; 
        stringUnit1 = [attributeDict objectForKey:@"unit1"];
        [arrayUnit1 addObject:stringUnit1];
    }
    if
        ([elementName isEqualToString:@"value2"]) {
        arrayUnit2 = [[NSMutableArray alloc] init];
        stringUnit2 = [attributeDict objectForKey:@"unit2"];
        [arrayUnit2 addObject:stringUnit2];
    }
}

To populate UITableView with value1 and value2 I’m using:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [arrayUnit1 count]; // <--- I Know, here is the problem!
}

…

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:
                UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
    }

    cell.textLabel.text = [NSString stringWithFormat:@"%@",[arrayUnit1 objectAtIndex:indexPath.row]];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",[arrayUnit2 objectAtIndex:indexPath.row]];

    return cell;
}

Well, the parsing is perfect, I can also NSLog every N stringValues but in my UITableView I can see ONLY ONE row with the LAST values of arrayUnit N (in this example unit1TimeN and unit2TimeN). So how can I populate the table with EVERY value, all the N values of my arrays? Maybe I need to implement also – (void)parser:(NSXMLParser *)parser didEndElement:? Thanks!

  • 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-17T05:57:30+00:00Added an answer on June 17, 2026 at 5:57 am

    remove this line from here

    arrayUnit1 = [[NSMutableArray alloc] init];

    and put it some where else when you allocate the parser..
    this is removing all previous elements of the array and allocing it new memory, so you will only see the last element added..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've an xml file that I would avoid having to load all in memory.
Using PHP I'm trying to parse very large xml files and insert them into
I have been searching all over the internet also in documentations about nested tags
Ok, I've been searching for all day to this problem. I have a loop,
I am using pyparsing to parse a hex string and I am searching for
While searching for a proper way to trim non-breaking space from parsed HTML, I've
Searching around I haven't found any recent answers to this question. The other answers
Searching here I found that this question was already asked , but I think
Searching from google.com, like www.abc.com Search Result Rank the pages like Title..... Description... www.abc.com
i'm using parse.com for the first time and searching for the way to get

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.