Row Count Is Returning the incorrect number using RaptureXML

I'm currently using RaptureXML to pull in data from a url tio display inside a table view. I've managed to grab every string I need and add it to my array, as you can see below:

- (void)loadURL { RXMLElement *rootXML = [RXMLElement elementFromURL:[NSURL URLWithString:@"http://api.somexml.com/xml"]]; NSLog(@"%@ %@", rootXML.tag, [rootXML attribute:@"totalEntries"]); [rootXML iterateWithRootXPath:@"//event" usingBlock:^(RXMLElement *event) { // NSLog(@"Event - URI: %@", [event attribute:@"uri"]); // NSLog(@"Event - Venue: %@", [event attribute:@"displayName"]); // NSLog(@"Event - Type: %@", [event attribute:@"type"]); [rootXML iterateWithRootXPath:@"//location" usingBlock: ^(RXMLElement *location) { // NSLog(@"Location - City: %@",[location attribute:@"city"]); // NSLog(@"Location - Latitude : %@",[location attribute:@"lat"]); // NSLog(@"Location - Longitude: %@",[location attribute:@"lng"]); [rootXML iterateWithRootXPath:@"//start" usingBlock:^(RXMLElement *start) { // NSLog(@"Start - Time: %@",[start attribute:@"time"]); // NSLog(@"Start - Date: %@",[start attribute:@"date"]); [rootXML iterateWithRootXPath:@"//performance" usingBlock:^(RXMLElement *performance) { // NSLog(@"Performance - Artist: %@",[start attribute:@"displayName"]); [events addObject:[NSArray arrayWithObjects: [event attribute:@"uri"], [event attribute:@"displayName"], [event attribute:@"type"], [location attribute:@"city"], [location attribute:@"lat"], [location attribute:@"lng"], [start attribute:@"time"], [start attribute:@"date"], [performance attribute:@"displayName"], nil]]; }]; }]; }]; }]; }

The problem is that when I assign the number of rows, it's returning a large number instead of 6.

return [events count];

This is what the XML file looks like:

<resultsPage totalEntries="6" perPage="50" page="1" status="ok"> <results> <event uri="http://somexml.com/xml" popularity="0.863682" displayName="Radio 1's Hackney Weekend 2012" id="9234656" type="Festival" status="ok"> <location city="London, UK" lng="-0.128" lat="51.5078"/> <series displayName="Radio 1's Hackney Weekend"/> <end time="" date="2012-06-24" datetime=""/> <start time="" date="2012-06-23" datetime=""/> <performance displayName="Lucy Labeaux" billingIndex="5" id="23336188" billing="headline"> <artist uri="http://www.somexml.com/artistxml" displayName="Lucy Labeaux" id="1168415"> <identifier href="http://somexml.com.xml" mbid="4593d49a-7f67-46ba-9ec0-126bd676286f"/> </artist> </performance>

Thank you for your help!


Getting Error related to my array's objects.


So I figured out something from constantly running the code. If you look below I add objects to my array 3 separate times.

- (void)loadURL { RXMLElement *rootXML = [RXMLElement elementFromURL:[NSURL URLWithString:@"http://somexml.com/xml"]]; NSLog(@"%@ %@", rootXML.tag, [rootXML attribute:@"totalEntries"]); [rootXML iterateWithRootXPath:@"//event" usingBlock:^(RXMLElement *event) { [events addObject:[NSArray arrayWithObjects: [event attribute:@"uri"], [event attribute:@"displayName"], [event attribute:@"type"], nil]]; }]; [rootXML iterateWithRootXPath:@"//location" usingBlock: ^(RXMLElement *location) { [events addObject:[NSArray arrayWithObjects: [location attribute:@"city"], [location attribute:@"lat"], [location attribute:@"lng"], nil]]; }]; [rootXML iterateWithRootXPath:@"//start" usingBlock:^(RXMLElement *start) { [events addObject:[NSArray arrayWithObjects: [start attribute:@"time"], [start attribute:@"date"], nil]]; }]; }

Now when I call my objects so I can link them to the interface I did the following:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { EventsCell *cell = (EventsCell *)[tableView dequeueReusableCellWithIdentifier:@"EventsCell"]; cell.venueLabel.text = [NSString stringWithFormat:@"%@",[[events objectAtIndex:indexPath.row] objectAtIndex:2]]; return cell;


I realized that instead of creating a total of 8 objects at index, it's only creating 3. And everytime I add new objects it's adding it to those 3 indexes. For example if I assign my Venue Label to the objectAtIndex 2, I not only get 6 rows with the label displaying the type, but also another 6 displaying the time.

This is how my viewDidLoad looks:

- (void)viewDidLoad { [super viewDidLoad]; self.events = [[NSMutableArray alloc] init]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self loadURL]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); }); }


Seeing that no one answered the question as an "answer" but left the answer in the comments, I'm going to just accept this as the answer.


  • ObjC, Facebook Page - posting news feed works, but posting photo does not
  • How to rotate app with TabBar?
  • Remove annotation while keeping plot matplotlib
  • How am I meant to release an array returned from a class method?
  • Check if a UITableViewCell is completely visible
  • find xml element by attribute
  • How do display a UIAlertView from a block on iOS?
  • iPhone dealing with xml vs soap vs JSON vs RESTful
  • How many View Controllers should I have in my game?
  • Buffer a large file; BufferedInputStream limited to 2gb; Arrays limited to 2^31 bytes
  • How Does Navigation in xamarin.forms Works?
  • Extracting individual digits from a float
  • Mongodb update() vs. findAndModify() performace
  • Insert audio album in Android MediaStore
  • It is possible use the same sql azure instance from two different cloud service of two different sub
  • NSMutableArray instance used in a block
  • Cut the background to expose the layer below
  • In matplotlib, how do you change the fontsize of a single figure?
  • How to make JSON.NET deserialize to Microsoft Date Time?
  • Combining two different ActiveRecord collections into one
  • Can someone please explain to me in the most layman terms how to use EventArgs?
  • How to remove a SwiftyJSON element?
  • Stop Bash Script if Hive Fails
  • Saving Changes After In-App Purchase Has Been Purchased
  • how to display data from 1st point on words on y axis for line chart in d3.js
  • Why querying a date BC is changed to AD in Java?
  • Illegal mix of collations for operation for date/time comparison
  • Is my CUDA kernel really runs on device or is being mistekenly executed by host in emulation?
  • Obtain ObjectIdHex value from mgo query
  • WinForms: two way TextBox problem
  • Release, debug version and Authorization Google?
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • Hits per day in Google Big Query
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • Bitwise OR returns boolean when one of operands is nil
  • UserPrincipal.Current returns apppool on IIS
  • How to push additional view controllers onto NavigationController but keep the TabBar?