Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从本地iPhone捆绑包读取xml_Xml_Xcode - Fatal编程技术网

从本地iPhone捆绑包读取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

我正在使用下面的代码从我的服务器读取一个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];
}

使用
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]]