iam developing one application.In that iam using the xml parsing.That xml file contain the 4 category tags and other tags.From the xml file i want to get the data of category tag.At the time of getting the category data,every time i print the array of category values.That show correctly.But after completion of parsing, another tag data will be append to last category name.My parsing code is like below.
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(self.presentvalue)
{
[presentvalue appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(![elementName compare:@"category"])
{
[categories addObject:presentvalue];
NSLog(@"%@",presentvalue);
NSLog(@"Number of elements %@",categories);
}
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"category"])
{
presentvalue=[NSMutableString string];
}
}
And my xml file content is like
<lesson>
<categories>
<category id="1">1</category>
<category id="2">2</category>
<category id="3">3</category>
</categories>
<references>
<reference id="1" type="youtube" categoryid="2" name="Boyles law">
<url><![CDATA[http://www.youtube.com/watch?v=J_I8Y-i4Axc]]>
</url>
</reference>
</references>
</lesson>
From this xml i got the array values like 1,2,3http://www.youtube.com/watch?v=J_I8Y-i4Axc.Like this i got the result.So please tell me how to get the category values without that extra data.
this should help u in your parsing. hope it helps. happy coding 🙂