Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
Objective c 我得到了XML数据,现在我如何在Objective C中保存XML数据?_Objective C_Xml - Fatal编程技术网

Objective c 我得到了XML数据,现在我如何在Objective C中保存XML数据?

Objective c 我得到了XML数据,现在我如何在Objective C中保存XML数据?,objective-c,xml,Objective C,Xml,作为Xcode 7中iOS开发的新版本。 下面我有一些问题,请澄清我的疑问 我需要存储URL中的XML数据 并将XML数据拆分为每行,并将其存储在Objective C中 8e268283-e87e-4abc-aab9-07cb611a8e60 40640054-2221-4086-92e4-4440497ccea2 La Parrilla哥伦比亚牛排馆;酒吧 La Parrilla哥伦比亚牛排馆;酒吧 PT8H31M PT18H50M 十二楼 当我开始学习XML解析时,它有一些基本的步骤。

作为Xcode 7中iOS开发的新版本。 下面我有一些问题,请澄清我的疑问

我需要存储URL中的XML数据 并将XML数据拆分为每行,并将其存储在Objective C中

8e268283-e87e-4abc-aab9-07cb611a8e60 40640054-2221-4086-92e4-4440497ccea2 La Parrilla哥伦比亚牛排馆;酒吧 La Parrilla哥伦比亚牛排馆;酒吧 PT8H31M PT18H50M 十二楼


当我开始学习XML解析时,它有一些基本的步骤。我为您实现所有这些

在ViewController.h中

步骤1:添加委托类

现在看来

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<NSXMLParserDelegate>
{
  NSXMLParser *parser;
  NSMutableData *ReceviedData;
  NSMutableString *currentStringValue;
  NSMutableArray *arrayID;
}
@end
第4步-在viewDidLoad中创建连接

现在,viewDidLoad方法是

- (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view from its nib.
   arrayID = [[NSMutableArray alloc]init];
   [self createConnection:@"http://www.google.com"]; //give your valid url.
}    
-(void)createConnection:(NSString *)urlString
{
     NSURL *url = [NSURL URLWithString:urlString];

    // Step 5 - parser delegate methods are using NSURLConnectionDelegate class or not.
    BOOL success;
    if (!parser)
    {
      parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
      parser.delegate = self;
      parser.shouldResolveExternalEntities = YES;
      success = [parser parse];
      NSLog(@"Success : %c",success);
    }
}
createConnection方法是

- (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view from its nib.
   arrayID = [[NSMutableArray alloc]init];
   [self createConnection:@"http://www.google.com"]; //give your valid url.
}    
-(void)createConnection:(NSString *)urlString
{
     NSURL *url = [NSURL URLWithString:urlString];

    // Step 5 - parser delegate methods are using NSURLConnectionDelegate class or not.
    BOOL success;
    if (!parser)
    {
      parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
      parser.delegate = self;
      parser.shouldResolveExternalEntities = YES;
      success = [parser parse];
      NSLog(@"Success : %c",success);
    }
}
步骤6-NSXMLParserDlegate方法如下


从上面的代码中,我只检查ID。根据您的回答,您需要比较其他键,如EstablishmentType、EstablishmentName、BusinessName、OpenTime……

您到底在看什么?提供您编写的XML数据结构和代码。@DipenPanchasara这是我的XML数据,先生。。。我需要这些Xml数据存储在Objective-C 8e268283-e87e-4abc-aab9-07cb611a8e60 40640054-2221-4086-92e4-4440497ccea2 La Parrilla Colombian Steakhouse&;巴拉帕里拉哥伦比亚牛排馆;条形图PT8H31M PT18H50M第12层用适当的格式填写您的问题,这样您就可以很容易地理解它。@DipenPanchasara我从url获得了XML数据,我需要将XML数据存储在目标c中。你能帮我吗?你可以参考一下XML解析。有了它的帮助,你可以很容易地做到。
- (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view from its nib.
   arrayID = [[NSMutableArray alloc]init];
   [self createConnection:@"http://www.google.com"]; //give your valid url.
}    
-(void)createConnection:(NSString *)urlString
{
     NSURL *url = [NSURL URLWithString:urlString];

    // Step 5 - parser delegate methods are using NSURLConnectionDelegate class or not.
    BOOL success;
    if (!parser)
    {
      parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
      parser.delegate = self;
      parser.shouldResolveExternalEntities = YES;
      success = [parser parse];
      NSLog(@"Success : %c",success);
    }
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    NSLog(@"Current Element Name : %@",elementName);
    if ([elementName isEqualToString:@"ID"])  //according to your xml response your id is Es_Id.So you need to compare @"Es_Id"
    {
         NSLog(@"The Result is==%@",elementName);
    }
}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    currentStringValue = [[NSMutableString alloc] initWithString:string];
    NSLog(@"Current String Value : %@",currentStringValue);
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementName isEqualToString:@"ID"]) //according to your xml response your id is Es_Id.So you need to compare @"Es_Id"
    {
       [arrayResult addObject:currentStringValue];
    }
       currentStringValue = nil;
}