Я пытаюсь проанализировать XML-файл, но не получаю подходящие проанализированные данные. Когда я получаю вывод в GDB, то я получаю двойное значение из тегов в XML-файле. вот мой код:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"found this element: %@", elementName);
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
// clear out our story item caches...
//item = [[NSMutableDictionary alloc] init];
blogtitle = [[NSMutableString alloc] init];
publishdate = [[NSMutableString alloc] init];
creator = [[NSMutableString alloc] init];
category = [[NSMutableString alloc] init];
description = [[NSMutableString alloc] init];
content = [[NSMutableString alloc] init];
}}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...
if ( [currentElement isEqualToString:@"title"]) {
[blogtitle appendString:string];
NSLog(@"blogtitle....%@",blogtitle);
}else if ([currentElement isEqualToString:@"pubDate"]) {
[publishdate appendString:string];
NSLog(@"publishdate....%@",publishdate);
}else if ([currentElement isEqualToString:@"dc:creator"]) {
[creator appendString:string];
NSLog(@"creator....%@",creator);
}else if ([currentElement isEqualToString:@"category"]) {
[category appendString:string];
NSLog(@"category....%@",category);
} if ([currentElement isEqualToString:@"description"]) {
[description appendString:string];
NSLog(@"description....%@",description);
} if ([currentElement isEqualToString:@"content:encoded"]) {
[content appendString:string];
NSLog(@"content....%@",content);
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"item"]) {
// save values to an item, then store that item into the array...
[item setObject:blogtitle forKey:@"title"];
[item setObject:publishdate forKey:@"pubDate"];
[item setObject:creator forKey:@"dc:creator"];
[item setObject:category forKey:@"category"];
[item setObject:description forKey:@"description"];
[item setObject:content forKey:@"content:encoded"];
[arr addObject:[item copy]];
// NSLog(@"adding story: %@", currentTitle);
}
}
вывод в GDB:
2011-08-11 17:32:49.651 the-life-doctor[5282:207] blogtitle....(null)
2011-08-11 17:33:02.897 the-life-doctor[5282:207] blogtitle....(null)
2011-08-11 17:33:07.760 the-life-doctor[5282:207] description....(null)
2011-08-11 17:33:09.217 the-life-doctor[5282:207] description....(null)
2011-08-11 17:33:10.559 the-life-doctor[5282:207] publishdate....(null)
2011-08-11 17:33:11.769 the-life-doctor[5282:207] publishdate....(null)
2011-08-11 17:33:24.104 the-life-doctor[5282:207] blogtitle....WHERE DOES LOVE LIVE
warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame.
warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame.
2011-08-11 17:35:34.265 the-life-doctor[5282:207] blogtitle....WHERE DOES LOVE LIVE
2011-08-11 17:35:39.053 the-life-doctor[5282:207] publishdate....Mon, 22 Nov 2010 17:43:47 +0000
2011-08-11 17:35:40.146 the-life-doctor[5282:207] publishdate....Mon, 22 Nov 2010 17:43:47 +0000
2011-08-11 17:35:40.644 the-life-doctor[5282:207] creator....admin
2011-08-11 17:35:41.236 the-life-doctor[5282:207] creator....admin
2011-08-11 17: 35: 41.898 the-life-doctor [5282: 207] категория .... ГДЕ ЛЮБИТ ЖИТЬ
2011-08-11 17: 35: 42.341 категория «доктор жизни» [5282: 207] .... ГДЕ ЛЮБИТ ЖИТЬ
вот мой xml файл:
Мне нужны значения из тега элемента, т. Е. Заголовка, pubDate, категории и т. Д., Но каждый раз значение выводится дважды. пожалуйста, помогите мне.