nsxml的作品,但不与我的服务

问题描述:

嗨iam写一个客户端服务器iPhone应用程序,我用nsxml从网站读取XML提要..and在我写了PHP服务之前,我试着用另一个网站的RSS ...它运行良好。nsxml的作品,但不与我的服务

但之后我写它不停的服务给我的错误代码76

所以我所做的是回声,我继承了早先从另一个网站收到我的PHP页面..和它完全相同的RSS提要仍然拒绝阅读它..它给了我相同的76代码错误! 错误解析XML:无法下载从网站的故事饲料(错误代码76)

- (void)parserDidStartDocument:(NSXMLParser *)parser { 
    NSLog(@"found file and started parsing"); 
} 

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { 
    NSString * errorString = [NSString stringWithFormat:@"Unable to download story feed from web site (Error code %i)", [parseError code]]; 
    NSLog(@"error parsing XML: %@", errorString); 
    UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [errorAlert show]; 
} 
- (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]; 
     currentTitle = [[NSMutableString alloc] init]; 
     currentDate = [[NSMutableString alloc] init]; 
     currentSummary = [[NSMutableString alloc] init]; 
     currentLink = [[NSMutableString alloc] init]; 
    } 
} 



- (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:currentTitle forKey:@"title"]; 
     [item setObject:currentLink forKey:@"link"]; 
     [item setObject:currentSummary forKey:@"summary"]; 
     [item setObject:currentDate forKey:@"date"]; 
     [stories addObject:[item copy]]; 
     NSLog(@"adding story: %@", currentTitle); 
    } 
} 
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ 
//NSLog(@"found characters: %@", string); 
// save the characters for the current item... 
    if ([currentElement isEqualToString:@"title"]) { 
     [currentTitle appendString:string]; 
    } else if ([currentElement isEqualToString:@"link"]) { 
     [currentLink appendString:string]; 
    } else if ([currentElement isEqualToString:@"description"]) { 
     [currentSummary appendString:string]; 
    } else if ([currentElement isEqualToString:@"pubDate"]) { 
     [currentDate appendString:string]; 
    } 
} 


- (void)parserDidEndDocument:(NSXMLParser *)parser { 
    NSLog(@"all done!"); 
    NSLog(@"stories array has %d items", [stories count]); 
    // [newsTable reloadData]; 
} 

海,你可以使用下面的代码,但要确保你正在做NSXMLParserDelegate

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

if(theConnection) 
{ 
// NSLog(@"theConnection.........%@",theConnection); 
    webData = [[NSMutableData data] retain]; 
} 
else 
{ 
    // NSLog(@"theConnection is NULL"); 
} 

这里theRequest包含URL网络服务。然后添加以下代码:

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 

[webData setLength: 0];} 


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
[webData appendData:data];} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
[connection release]; 
[webData release];} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection { 
if(xmlParser) 
{ 
    [xmlParser release]; 
} 

xmlParser = [[NSXMLParser alloc] initWithData: webData]; 
[xmlParser setDelegate: self]; 
[xmlParser setShouldResolveExternalEntities: YES]; 
[xmlParser parse]; 

[connection release]; 
[webData release]; 
} 

然后您应该使用您的解析委托方法。我希望它能正常工作

+0

干草让我知道它是否在工作,以便我可以帮助你一点点 – sandy

+0

这是没问题的每个机构..问题是我有一个空的节点在我的XML .. ..我的坏.... thnx沙你的超级真棒人.. – user1083237