This is the XML data:
<Categorys>
<Category>
<categoryId>25</categoryId>
<categoryName>My Photos</categoryName>
<categoryDescription>Description</categoryDescription>
<categoryIconPath>7.jpg</categoryIconPath>
<userId>2</userId>
<categoryStatus>ON</categoryStatus>
<publicPrivate>Private</publicPrivate>
</Category>
......more categories
<Categorys>
Here I want to get the <categoryName>
values into my NSMutableArray categList
.
The code I have used is:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary*)attributeDict {
if ( [elementName isEqualToString:@"categList"]) {
// addresses is an NSMutableArray instance variable
if (!categList)
categList = [[NSMutableArray alloc] init];
return;
}
NSLog(@"StartedElement %@", elementName);
element = [NSMutableString string];
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(element == nil)
element = [[NSMutableString alloc] init];
[element appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
NSLog(@"Found an element named: %@ with a value of: %@", elementName, element);
if ([elementName isEqualToString:@"categoryName"]) {
NSLog(@"
found::::::::::::::: %@", element);
category = element;
NSLog(@"category:::: %@", category);
}
[categList addObject:element];
NSLog(@"categList*************** %@", categList);
}
But I am not getting the category names in my NSMutableArray categList
:
Whats wrong in my code? :(
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…