Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Trying to return first instance of element from xml
Im trying to get the value of an attribute from an XML the attribute appear more than once and I only want to return the result once . here is the XML from the server and my attempted code
As you see the line in bold appears twice. I am logging the value of attribute 'L' when the 'S' attribute is equal to string @"342". The NSLog shows both occurrences and as I will eventually (and this is also proving more difficult that I would have thought but thats another hurdle for another time) put the result into a UILabel I only want it to return the result once and ignore if it appears again in the XML.
The code im trying is
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { BOOL=NO; if (!BOOL) { if ([elementname isEqualToString:@\"T\"]){ myString =[[NSString alloc]init]; if ([[attributeDict objectForKey:@\"S\"]isEqualToString:@\"342\"]) { BOOL=YES; } if (BOOL) { myString=[attributeDict objectForKey:@\"L\"]; NSLog(@\"%@\",myString); } } }}
Does this code actually compile without errors & warnings? I say this because "BOOL" is a reserved word, and you're using it like the name of one of your ivars.
Does this code actually compile without errors & warnings? I say this because "BOOL" is a reserved word, and you're using it like the name of one of your ivars.
It does yes in my code the BOOL is actually resultIsAcheived I just changed to BOOL for purpose of the forum so it easier indicates that it is a Boolean.
I think I've figured it out, although I can't test it yet as I'm at work. Surely if I add the results returned to an NSMutableArray and call objectAtIndex method it can only return one instance as each instance would obviously have its own index! If this is flawed let me know as I won't be able to test for hours :-)
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSurely if I add the results returned to an NSMutableArray and call objectAtIndex method it can only return one instance as each instance would obviously have its own index! If this is flawed let me know as I won't be able to test for hours :-)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome