I'm using TBXML to parse one xml file. Almost everything works well. It goes into the tableview and everything. There is one problem. The array only seems to be holding the final element and repeating it for however many number of other elements i have. I don't think that made too much sense so here is what I mean.
Code:
<thing>
<otherThing title = "hi">
<des> hi everyone</des>
</otherThing>
<otherThing title = "yea">
<des> sup</des>
</otherThing>
</thing>
It will repeat otherThing with the title of yea twice instead of putting both of them.
Here is my code.
Code:
- (void)load{
array= [[NSMutableArray alloc] initWithCapacity:10];
// error var
NSError *error = nil;
// Load and parse the books.xml file
tbxml = [TBXML tbxmlWithXMLFile:@"books.xml" error:&error];
// if an error occured, log it
if (error) {
NSLog(@"Error! %@ %@", [error localizedDescription], [error userInfo]);
} else {
// Obtain root element
TBXMLElement * root = tbxml.rootXMLElement;
// if root element is valid
if (root) {
// search for the first author element within the root element's children
TBXMLElement * author = [TBXML childElementNamed:@"otherThing" parentElement:root];
// if an author element was found
while (author != nil) {
// instantiate an author object
Author * anAuthor = [[Author alloc] init];
// get the name attribute from the author element
anAuthor.name = [TBXML valueOfAttributeNamed:@"title" forElement:author];
// add our author object to the authors array
[array addObject:anAuthor];
// find the next sibling element named "author"
author = [TBXML nextSiblingNamed:@"otherThing" searchFromElement:author];
}
}
}
}
Are you sure you want to cop an attitude with someone who WAS trying to help you. Okay fine then.
I'm not getting an attitude. I honestly didn't mean to do that and I'm sorry, like I said.
All I said was chill, nothing with offensive intent.
The way you came across by saying I was wasting your time led me to believe you were pretty angry. Likewise, I said chill to potentially alleviate your anger.
This is getting good; hang on while I make some popcorn.
Seriously, though, I do agree with timle8n1; you should post only actual code, not "remembered" code. Because there's no way anyone could do that accurately, and examining it therefore has no value.
So hopefully you'll update the thread with real code. In the meantime, have you tried the obvious step of logging your array at the end of your load method to see what's in it?
__________________ Recall It!Tag your notes. Tag your photos. Tag your thoughts. Tag your life.
This is getting good; hang on while I make some popcorn.
Seriously, though, I do agree with timle8n1; you should post only actual code, not "remembered" code. Because there's no way anyone could do that accurately, and examining it therefore has no value.
So hopefully you'll update the thread with real code. In the meantime, have you tried the obvious step of logging your array at the end of your load method to see what's in it?
Will do, and I'm really sorry about that. I'll fix it.
Yes, I have. I probably should have included that as well.
I get the same thing I get in the tableview. However, because it is logged, I see a little more. Let me show you what I mean.