2013-02-18 101 views
-1

我在IOS是新的。我一直在寻找如何从我的ressources本地XML文件中读取一个政党成员或小的例子,但我什么也没找到....具有良好的政党成员的任何一个或对XML的工作之前,我真的需要你的帮助IOS和XML解析器(读文件)

+0

http://stackoverflow.com/questions/11323326/xml-parsing-in-ios-tutorial – 2013-02-18 09:48:56

+0

一个很简单的例子http://stackoverflow.com/questions/9109032/如何阅读,HTML-AS-XML功能于iphone/9109924#9109924 – 2013-02-18 10:43:11

+0

[为Java最好的XML解析器(可能重复http://stackoverflow.com/questions/373833/best-xml-parser-for -java) – 2013-06-05 01:55:06

回答

0

您可以使用下面的代码读取XML文件:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"myLocalXML" ofType:@"xml"]; 
    if (filePath) 
    { 
     NSString *myText = [NSString stringWithContentsOfFile:filePath]; 
     if (myText) 
     { 
      NSLog(@"XML : %@",myText); 
      NSData *xmlData = [myText dataUsingEncoding:NSUTF8StringEncoding]; 
      NSXMLParser *parser = [[NSXMLParser alloc] initWithData:xmlData]; 
      parser.delegate = self; 
      [parser parse]; 
     } 
    }