我正在使用以下代码从我的服务器读取xml及其100%工作
我需要从我的应用包中读取相同的xml,那么我将在此功能中更改以实现我的目标?
-(void)openXML {
NSURL *url = [NSURL URLWithString:@"http://mydomain/data.xml"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:req delegate:self];
con release];
myData = [[NSMutableArray alloc] init];
}
答案 0 :(得分:4)
使用NSBundle
课程访问您应用的捆绑资源。
NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"xml"];
NSURL *url = [NSURL fileURLWithPath:path]; //here you have to pass the filepath
答案 1 :(得分:0)
我希望这会
NSString * pathStr = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@“sample.xml”]; NSData * dataXml = [NSData dataWithContentsOfURL:[NSURL URLWithString:pathStr]];