从本地iPhone捆绑包读取xml
我正在使用下面的代码从我的服务器读取一个xml,它可以100%正常工作 我需要从我的应用程序包中读取相同的xml,那么为了实现我的目标,我将在这个函数中更改什么从本地iPhone捆绑包读取xml,xml,xcode,Xml,Xcode,我正在使用下面的代码从我的服务器读取一个xml,它可以100%正常工作 我需要从我的应用程序包中读取相同的xml,那么为了实现我的目标,我将在这个函数中更改什么 -(void)openXML { NSURL *url = [NSURL URLWithString:@"http://mydomain/data.xml"]; NSURLRequest *req = [NSURLRequest requestWithURL:url]; NSURLConnection *con = [[NSUR
-(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];
}
使用
NSBundle
类访问应用程序的捆绑资源
NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"xml"];
NSURL *url = [NSURL fileURLWithPath:path]; //here you have to pass the filepath
使用
NSBundle
类访问应用程序的捆绑资源
NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"xml"];
NSURL *url = [NSURL fileURLWithPath:path]; //here you have to pass the filepath
我希望这会发生
NSString*pathStr=[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@“sample.xml”];
NSData*dataXml=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathStr]] 我希望这会发生
NSString*pathStr=[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@“sample.xml”];
NSData*dataXml=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathStr]]