我创建了一个iPhone应用程序,用于阅读 this XML,但在从其他位置读取其他XML文件时,它无法使用此链接。
任何人都可以测试一下,看看你是否可以阅读?如果是,你可以告诉我怎么做?
答案 0 :(得分:0)
快速测试,工作得很好......
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *XMLEncodedString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://minihath.com/events/XMLfeeds.xml" ]];
NSData *data = [XMLEncodedString dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *xml = [[NSXMLParser alloc] initWithData:data];
[xml setDelegate:self];
[xml setShouldResolveExternalEntities:YES];
[xml parse];
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
NSLog(@"Error: %@", [parseError localizedDescription]);
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentElementValue = [[NSMutableString alloc] init];
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *) string {
[currentElementValue appendString:string];
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *) elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
NSLog(@"elementName %@ %@", elementName, currentElementValue);
currentElementValue=nil;
[currentElementValue release];
}