2010-12-20 59 views
0

我使用元素解析器從本地文件中解析一些xml,但我希望能夠從Web中檢索此xml文件,然後用Element Parser解析它。但是,當我嘗試使用NSURL來獲取xml文件時,我的應用程序崩潰。到目前爲止,我嘗試使用的代碼是:如何從元素解析器的網址獲取xml文件

NSURL *url = [[NSURL alloc] initWithString:@"http://example.com/file.xml"] 

我使用的檢索本地XML文件中的代碼是:

NSString* path = [[NSBundle mainBundle] pathForResource: @"file" ofType: @"xml"]; 
NSStringEncoding encoding; 
self.source = [NSString stringWithContentsOfFile: path usedEncoding: &encoding error:  NULL]; 
DocumentRoot *document = [Element parseXML:source]; 

那麼,如何才能做到這一點?我也試圖做parseXMLFromURL,但它不起作用,所以我迷路了。任何幫助將非常感激。謝謝

+0

哪裏是你使用的這個解析器的文檔?我搜索了它,並找不到任何對「元素」解析器的引用。 – chuckSaldana 2010-12-20 04:35:23

+0

唯一的文檔是從這裏:http://touchtank.wordpress.com/element-parser/ – 0SX 2010-12-20 04:46:18

回答

1
NSString *stringUrl = @"http://yourDomain.com/yourXml" 
    NSURL *finalURL = [NSURL URLWithString:[stringUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; 
    NSString *xmlString = [NSString stringWithContentsOfURL:finalURL  
                encoding:NSUTF8StringEncoding 
                 error:nil]; 
+0

謝謝你!救生員:-) – 0SX 2010-12-21 04:52:28