0

我正在尝试使用 NSXMLParser 解析一个简单的 XML 文件……这是我的代码……

    -(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”......出了什么问题?

4

1 回答 1

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];
    }
}

我希望这可以帮助你...

于 2012-12-06T07:09:04.637 回答