im trying to parse the child data which is sub_category and show it, but will only show the relevant sub_category of the parent category. I was sucessful in parsing the data of the parent element but im having a problem on how to parse the child element.
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"category"]){
dataCurrent = [dataFileHolder alloc];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
currentList = [[NSMutableString alloc] initWithString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"name"]){
dataCurrent.nameOfCat = currentList;
}
if ([elementName isEqualToString:@"description"]){
dataCurrent.descriptionOfCat = currentList;
}
if ([elementName isEqualToString:@"image"]) {
dataCurrent.imageLink = currentList;
}
if ([elementName isEqualToString:@"category"]) {
[listPopulated addObject:dataCurrent];
dataCurrent = nil;
currentList = nil;
}
}
and the XML file is like this
<category>
<name>Food</name>
<description>food description</description>
<image> Link Here </image>
<sub_cat>
<sub_name>Sub name</sub_name>
<sub_desc>sub cat description</sub_desc>
<sub_image> Link </sub_image>
</sub_cat>
<sub_cat>
<sub_name>Sub name</sub_name>
<sub_desc>sub cat description</sub_desc>
<sub_image> Link </sub_image>
</sub_cat>
</category>
and I been researching about the Event Driven XML Parsing and also find a gud reference from one of the threads xml-parse-only-certain-child-elements, but at the end im still pretty confuse about the XML and parsing stuff. I might need a lamer term. And would like to know on how to do my parsing part.