Мой NSXMLParser протекает, и я не знаю почему!В подробностях говорится, что источник на 100% состоит из [Parser parse]
;
Изображение: Утечки инструментов
Это мой код для выделения и выпускаNSXMLParser:
NSURL *xmlURL = [NSURL URLWithString:@"http://www.website.com/link.xml"];
NSData * dataXml = [[NSData alloc] initWithContentsOfURL:xmlURL];
Parser = [[NSXMLParser alloc] initWithData:dataXml];
[dataXml release];
Parser.delegate = self;
[Parser parse];
[Parser release];
Методы делегата
//Standard function parser: reading open tag
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict{
currentElement = elementName;
if ([elementName isEqualToString:@"item"]) {
xmlArray = [[NSMutableDictionary alloc] init];
}
}
//Standard function parser: reading string
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if ([currentElement isEqualToString:@"created_time"]){
valueKey = [xmlArray valueForKey:currentElement];
if(nil != valueKey)
{
valueKey = [valueKey stringByAppendingString:string];
}else
{
valueKey = string;
}
[xmlArray setObject:valueKey forKey:currentElement];
}
if ([currentElement isEqualToString:@"message"]){
valueKey = [xmlArray valueForKey:currentElement];
if(nil != valueKey)
{
valueKey = [valueKey stringByAppendingString:string];
}else
{
valueKey = string;
}
[xmlArray setObject:valueKey forKey:currentElement];
}
if ([currentElement isEqualToString:@"picture"]){
valueKey = [xmlArray valueForKey:currentElement];
if(nil != valueKey)
{
}else
{
valueKey = string;
}
[xmlArray setObject:valueKey forKey:currentElement];
}
}
//Standard function parser: reading close tag
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"item"]) {
Post *newPost = [[Post alloc] init];
newPost.created_time = [xmlArray objectForKey:@"created_time"];
newPost.message = [xmlArray objectForKey:@"message"];
newPost.picture = [xmlArray objectForKey:@"picture"];
[containerArray addObject:newPost];
[xmlArray release];
[newPost release];
}
}