我正在尝试使用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”......出了什么问题?
答案 0 :(得分: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];
}
}
我希望这可以帮助你...