csaki

xmlparser

May 7th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  ViewController.m
  3. //  konyvtarAlk
  4. //
  5. //  Created by Admin on 2014.05.07..
  6. //  Copyright (c) 2014 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController ()
  12.  
  13. @end
  14.  
  15. @implementation ViewController
  16. @synthesize inputTitleField;
  17. @synthesize inputNameField;
  18. @synthesize messages;
  19.  
  20. - (void)viewDidLoad
  21. {
  22.     [super viewDidLoad];
  23.     // Do any additional setup after loading the view, typically from a nib.
  24.     // szerző, könyvcím, kiadás éve (author, title, date)
  25.     inputNameField.text = @"";
  26.     post = @"command=<SelectDatabase id=\"ekfkdb\"/>";
  27.     postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
  28.    
  29.     postLength = [NSString stringWithFormat:@"%d", [postData length]];
  30.    
  31.     request = [[NSMutableURLRequest alloc] init];
  32.    
  33.     [request setURL:[NSURL URLWithString:@"http://m.corvina.ektf.hu"]];
  34.     [request setHTTPMethod:@"POST"];
  35.     [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  36.     [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  37.     [request setHTTPBody:postData];
  38.     error = nil;
  39.     response = nil;
  40.     data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  41.     NSLog(@"%@",request);
  42.     if (error) {
  43.         NSLog(@"Error:%@", error.localizedDescription);
  44.     }
  45.     else {
  46.         mywebdata=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  47.         [outputview loadHTMLString:mywebdata baseURL:nil];
  48.         NSLog(@"%@", mywebdata); // működik
  49.     }
  50.    
  51. }
  52.  
  53. -(void)search
  54. {
  55.     post = [[NSString alloc] initWithFormat:@"command=<SelectObj objClasses=\"corvina.obj.MarcData\" xmlForm=\"TypeName\"><And><AttributeFilter attribute=\"Author_name\" term=\"%@\"/><AttributeFilter attribute=\"Title\" term=\"%@\"/></And><Obj class=\"corvina.obj.CatRecordInfo_Bibl\"/></SelectObj>", inputNameField.text, inputTitleField.text];
  56.     NSLog(@"\n\n%@\n\n", post);
  57.     postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
  58.     postLength = [NSString stringWithFormat:@"%d", [postData length]];
  59.    
  60.     request = [[NSMutableURLRequest alloc] init];
  61.    
  62.     [request setURL:[NSURL URLWithString:@"http://m.corvina.ektf.hu"]];
  63.     [request setHTTPMethod:@"POST"];
  64.     [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  65.     [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  66.     [request setHTTPBody:postData];
  67.     error = nil;
  68.     response = nil;
  69.     data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  70.     NSLog(@"%@",request);
  71.     if (error) {
  72.         NSLog(@"Error:%@", error.localizedDescription);
  73.     }
  74.     else {
  75.         mywebdata=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  76.         [outputview loadHTMLString:mywebdata baseURL:nil];
  77.         NSLog(@"%@", mywebdata); // műkö
  78.        
  79.         [self messageReceived:mywebdata];
  80.     }
  81. }
  82.  
  83.  
  84.  
  85. -(void)messageReceived:(NSString *)message
  86. {
  87.     parser=[[NSXMLParser alloc] initWithData:[message dataUsingEncoding:NSUTF8StringEncoding]];
  88.     parser.delegate=self;
  89.     [parser parse];
  90. }
  91.  
  92. - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
  93. {
  94.     if ([elementName isEqualToString:@"CatRecordInfo_Bibl"])
  95.     {
  96.        
  97.     }    
  98. }
  99.  
  100. - (void)viewDidUnload
  101. {
  102.     [super viewDidUnload];
  103.     // Release any retained subviews of the main view.
  104. }
  105.  
  106. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  107. {
  108.     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  109. }
  110.  
  111. @end
Advertisement
Add Comment
Please, Sign In to add comment