I am new to iphone development.I am parsing an XML page and displaying the content in a tableview.In some block in the XML page , the child element is missing , i want to add a value o in my array, when the child element is not fond in the particular block.My XML file is like
<entry>
<id>xxx </id>
<title>xxxxx</title>
<gd:ratings numRaters="2"/>
</entry> ..................................>first block
<entry>
<id>xxx </id>
<title>xxxxx</title>
</entry> ....................................>Second block
<entry>
<id>xxx </id>
<title>xxxxx</title>
<gd:ratings numRaters="2"/>
</entry> .....................................>Third block
I am parsing the gd:ratings tag and display its attribute numRates value in a tableview. I am having an mutable array which stores the value of numRates.I have to add object "O" in the array when the second block is parsed because it doesnot contain gd:ratings tag.Since the value is present in a attribute tag, for retrieving the content and adding it to the mutable array is done in NSXML parser DidStartElement method.
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"entry"]) {
entry = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
NSLog(@"inside image1 ");
}else if([elementName isEqualToString:@"media:thumbnail"])
{ currentImage = [[NSMutableString alloc] init];
if(myUrl == nil){
myUrl = [NSString stringWithString:[attributeDict objectForKey:@"url"]];
}
[currentImage appendString:myUrl];
[stories1 addObject:currentImage];
myUrl=nil;
} else if([elementName isEqualToString:@"gd:rating"])
{
currentRating=[[NSMutableString alloc]init];
myRatings=[NSString stringWithString:[attributeDict objectForKey:@"numRaters"]];
[currentRating appendString:myRatings];
[stories2 addObject:currentRating];
}
}
Since there are 25 blocks of entry tags and in that 10 block doesnot have gd rating element .So the array stories2 array has only 15 values.So i cannot display it in the tableview in order.Is there any way out to retrieve the attribute tag in "found characters" method . Please help me out.Thanks.