读取documents/test目录下的xml文档
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSMutableString* str = [NSMutableString stringWithString:documentsDirectory];
[str appendString:@"/test/"];
[str appendString:@"xmlfile.xml"];
NSLog(@"documentsDirectory %@",str);
NSURL *url = [NSURL fileURLWithPath:[XMLParser fullPathFromRelativePath:str]];
NSXMLParser* rssParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
解析响应
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSString *errorString = [NSString stringWithFormat:@"Error code %li", (long)[parseError code]];
NSLog(@"Error parsing XML: %@", errorString);
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
// NSLog(@"parser %@",elementName);
}