2012-12-06 53 views
0
解析的

我試圖解析用的NSXMLParser一個簡單的XML文件......這是我的代碼..XML沒有被用的NSXMLParser

-(void) parseXml{   
     NSString *XmlPath=[[NSBundle mainBundle] pathForResource:@"myXML" ofType:@"xml"];   
     //NSLog(@"%@",XmlPath); path found!  

     NSData *xml=[[NSData alloc] initWithContentsOfFile:XmlPath]; 
     //NSLog(@"%@",Xml); outputs : xml in hexadecimal coded form 

     self.Xmlparser=[[NSXMLParser alloc]initWithData:xml]; 
     //NSLog(@"%@",self.Xmlparser); outputs : some hexadecimal code 

     self.Xmlparser.delegate=self; 

     NSLog(@"%@",self.Xmlparser);   

     if([self.Xmlparser parse]) 
      NSLog(@"PARSED"); 
     else 
      NSLog(@"NotPARSED"); 
    } 

輸出爲「NotPARSED」 ......什麼錯誤?

回答

0

嘿,你可以檢查其解析或不在其委託的方法是波紋管..

- (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]; 
    NSLog(@"NotPARSED"); 
} 



- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI 
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict 
{ 
    NSLog(@"PARSED"); 
    if([elementName isEqualToString:@"item"]){ 
     currentFilm  = [Film alloc]; 
     currentNodeContent =[[NSMutableString alloc] init]; 
    } 
} 

我希望這會幫助你...

+0

是thanks..i使用' - (空)解析器:(NSXMLParser *)解析器parseErrorOccurred:(NSError *)parseError'並得到alertView ...我應該如何調試什麼是錯的!? – BaSha

+0

這裏沒有任何錯誤的傢伙只實現我們班級相關的委託方法.. –

+1

它完成了! ......在我的xml文件的問題...我驗證它http://validator.w3.org/check和解決錯誤!現在它的工作.. – BaSha