我正在创建一个需要读取XML 文件的 iPhone 应用程序
特性
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *fileName;
@property (nonatomic, strong) NSString *description;
@property (nonatomic, strong) NSString *date;
@property (nonatomic, strong) NSString *link;
搜索标签(此处仅用于“标题”)
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
// FIRST TAG XML
if([elementName isEqualToString:@"title"]){
// GET DATA FROM XML
getData = YES; // getData is a bool which is NO initialy
NSLog(@"Found");
}
else
NSLog(@"Not Found");
}
获取数据
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if(getData)
{
// CREATION DE L OBJET DEPUIS LE XML
NSLog(@"This is your desired data = %@",string);
NSLog(@"Object creation ...");
Pebkac *peb = [[Pebkac alloc] init];
NSLog(@"Setup the name ...");
[peb setName:@"Pebkac"];
NSLog(@"Small descrption ...");
[peb setDescription:string];
[pebkacs addObject:peb];
}
}
结束标签
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
// XML END TAG
if ([elementName isEqualToString:@"title"]){
getData = NO;
}
}
我观察到的错误是,有时它无法获取标签之间的所有文本。