简体   繁体   English

RaptureXML无法从用户路径加载数据

[英]RaptureXML could not load data from user path

I'm new to iOS development. 我是iOS开发的新手。 I've found RaptureXML and it works quiet well but I could not load data which I stored in my user directory. 我已经找到了RaptureXML ,它可以安静地运行,但是无法加载存储在用户目录中的数据。 Having a "data.xml" within my application directory works fine, I could load it with [RXMLElement elementFromXMLFile:@"data.xml"]; 我的应用程序目录中有一个“ data.xml”,可以正常工作,我可以用[RXMLElement elementFromXMLFile:@"data.xml"];加载它[RXMLElement elementFromXMLFile:@"data.xml"]; . But now I have downloaded a file from Internet and stored it in my user directory using these lines: 但是现在我已经从Internet下载了一个文件,并使用以下几行将其存储在我的用户目录中:

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"data.xml"];

The computed file path is 计算的文件路径是

"/Users/ myname /Library/Application Support/iPhone Simulator/6.0/Applications/ myapplicationguid /Documents/data.xml" “ / Users / myname / Library / Application Support / iPhone Simulator / 6.0 / Applications / myapplicationguid /Documents/data.xml”

.

The file exists, I've checked with [[NSFileManager defaultManager] fileExistsAtPath:filename]; 该文件存在,我已经使用[[NSFileManager defaultManager] fileExistsAtPath:filename]; . I've also opened it manually and placed the value from the example XML File from RaptureXML there, so it could not be any mismatches within the XML or else.... 我还手动打开了它,并将RaptureXML的示例XML文件中的值放置在那里,因此它在XML内不会有任何不匹配。

But when I use [RXMLElement elementFromXMLFile:filename] it does not return anything... Any ideas? 但是,当我使用[RXMLElement elementFromXMLFile:filename]它不返回任何内容。

I've now made a workaround: As direct access does not work, I'm first loading the data using standard functions and then transfer the NSData to RaptureXML like this: 我现在采取了一种解决方法:由于直接访问不起作用,因此我首先使用标准函数加载数据,然后将NSData传输到RaptureXML,如下所示:

 NSError *error;
    NSString* contents = [NSString stringWithContentsOfFile:filename
                                                   encoding:NSUTF8StringEncoding
                                                      error:&error];
    NSData* xmlData = [contents dataUsingEncoding:NSUTF8StringEncoding];

    RXMLElement *rss = [RXMLElement elementFromXMLData:xmlData];

最好使用initFromXMLFilePath:方法。

 RXMLElement *rss = [[RXMLElement alloc]initFromXMLFilePath: filePath];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM