You are iterating over the wrong elements. NSArray *successStoryArray = [stories elementsForName:@"storyid"];
will get two elements: storyid with value=1 and storyid with value=2.
Then you iterate over those elements and trying to extract title and picture, but title and picture are not child elements of . Title and picture are at the same level as storyid, they are children of .
There are two ways to fix it:
Extract 3 arrays, each containing the values for storyid, title and picture
NSArray *successStoryArray = [stories elementsForName:@"storyid"];
NSArray *titleArray = [stories elementsForName:@"title"];
NSArray *pictureArray = [stories elementsForName:@"picture"];
Then you can iterate them in order and items will match
Even better in my opinion, change the structure of the XML by wrapping each story in a element, like this:
<iq type="result">
<stories xmlns="success">
<story>
<storyid>1</storyid>
<title>THE TITLE</title>
<picture>BASE64EncodedStringOfImage</picture>
</story>
<story>
<storyid>2</storyid>
<title>Love At First Site</title>
<picture>BASE64EncodedStringOfImage</picture>
</story>
</stories>
</iq>
Then you can do:
NSXMLElement *stories = [iq elementForName:@"stories"];
NSArray *successStoryArray = [stories elementsForName:@"story"];
NSLog(@"successStoryArray: %@", successStoryArray);
for (NSXMLElement *i in successStoryArray)
{
NSXMLElement *storyId = [i elementForName:@"storyId"];
NSString *sId = [storyId stringValue];
NSLog(@"sId: %@", sId);
NSXMLElement *title = [i elementForName:@"title"];
NSString *sTitle = [title stringValue];
NSLog(@"sTitle: %@", sTitle);
NSXMLElement *picture = [i elementForName:@"picture"];
NSString *sPicture = [picture stringValue];
NSLog(@"sPicture: %@", sPicture);
}