zoukankan      html  css  js  c++  java
  • GData MyASIUpLoadImage WebXMLParser

    #import <UIKit/UIKit.h>
    #import "GDataXMLNode.h"
    @interface ZYKAppDelegate : UIResponder <UIApplicationDelegate>
    {
        //声明xml文档解析成员变量
        GDataXMLDocument *_doc;
    }
    @property (strong, nonatomic) UIWindow *window;
    
    @end
    
    #import "ZYKAppDelegate.h"
    
    @implementation ZYKAppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
      
        [self xmlXpathParser2];
        
        
        
        
        
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }
    //逐层解析
    -(void)xmlParser
    {
        
        NSString *strURL=[[NSBundle mainBundle]pathForResource:@"xml" ofType:@"txt"];
        NSString *strContent=[[NSString alloc]initWithContentsOfFile:strURL encoding:NSUTF8StringEncoding error:nil];
        //实例化
        _doc=[[GDataXMLDocument alloc]initWithXMLString:strContent options:0 error:nil];
        GDataXMLElement *rootElement=[_doc rootElement];
        //在跟节点里边查找books子元素
        NSArray *booksArray=[rootElement elementsForName:@"books"];
        //从数组中获得books子元素
        GDataXMLElement *booksElement=[booksArray objectAtIndex:0];
        
        //在books节点里边查找book子元素
        NSArray *bookArray=[booksElement elementsForName:@"book"];
        //从数组中获得第二个book元素
        GDataXMLElement *secondBookElement=[bookArray objectAtIndex:1];
        
        //在第二个book元素中查找name自元素
        NSArray *nameArray=[secondBookElement elementsForName:@"name"];
        GDataXMLElement *nameElement=[nameArray objectAtIndex:0];
        NSLog(@"%@",nameElement.stringValue);
        
        
    }
    
    //xPath解析
    -(void)xmlXpathParser
    {
        NSString *strURL=[[NSBundle mainBundle]pathForResource:@"xml" ofType:@"txt"];
        
        //将路径下文件得内容加载到字符串中
        NSString *strContent=[[NSString alloc]initWithContentsOfFile:strURL encoding:NSUTF8StringEncoding error:nil];
        _doc=[[GDataXMLDocument alloc]initWithXMLString:strContent options:0 error:nil];
        //获得文档得根节点
        GDataXMLElement *rootElement=[_doc rootElement];
        //查找制定路径下得节点
        //xPath目录必须从根路径开始,而且不能层次跳跃
        //通过xPath方法查找得元素为xPath路径尾部(@"/根节点/子节点/.../尾节点")的元素
        NSArray *array= [rootElement nodesForXPath:@"/root/books/book" error:nil];
        GDataXMLElement *secondBookElement=[array objectAtIndex:1];
        
        //在第二个book元素中查找name子元素
        NSArray *nameArray=[secondBookElement elementsForName:@"name"];
        GDataXMLElement *nameElement=[nameArray objectAtIndex:0];
        //获得name元素的值
        NSLog(@"%@",nameElement.stringValue);
        
        
        
        
        
        
        
        
    }
    
    
    -(void)xmlXpathParser2
    {
        
        NSString *strURL=[[NSBundle mainBundle]pathForResource:@"xml" ofType:@"txt"];
        
        //将路径下文件得内容加载到字符串中
        NSString *strContent=[[NSString alloc]initWithContentsOfFile:strURL encoding:NSUTF8StringEncoding error:nil];
        _doc=[[GDataXMLDocument alloc]initWithXMLString:strContent options:0 error:nil];
        //获得文档得根节点
        GDataXMLElement *rootElement=[_doc rootElement];
        
        //如果xPath路径为//节点,那么文件中所有的该节点都会被查找到
        NSArray *array=[rootElement nodesForXPath:@"//name" error:nil];
        for (GDataXMLElement *nameElement in array) {
            NSLog(@"%@",nameElement.stringValue);
        }
        
    }
    #import <UIKit/UIKit.h>
    #import "ASIFormDataRequest.h"
    @interface FirstViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate,ASIHTTPRequestDelegate>
    {
        //声明相册控制器
        UIImagePickerController *_pickerController;
        
        //可以上传图片和字符串
        ASIFormDataRequest *_request;
        UIImage *image;
        
    }
    @property (weak, nonatomic) IBOutlet UIImageView *imgView;
    - (IBAction)btnClick:(id)sender;
    - (IBAction)upLoadClick:(id)sender;
    - (IBAction)loginBtnClick:(id)sender;
    @property (weak, nonatomic) IBOutlet UITextField *nameTextField;
    @property (weak, nonatomic) IBOutlet UITextField *pwdTextField;
    
    @end
    
    #import "FirstViewController.h"
    
    @interface FirstViewController ()
    
    @end
    
    @implementation FirstViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (IBAction)btnClick:(id)sender {
        
        //实例化相册
        _pickerController=[[UIImagePickerController alloc]init];
        _pickerController.delegate=self;
        [self presentViewController:_pickerController animated:YES completion:^{
            
        }];
        
        
        
        
    }
    
    - (IBAction)upLoadClick:(id)sender {
        
        
        
        NSURL *url=[NSURL URLWithString:@"http://10.0.8.8/sns/my/upload_photo.php"];
        _request=[[ASIFormDataRequest alloc]initWithURL:url];
        _request.delegate=self;
        //设置上传方式(post比get传输更安全)
        [_request setRequestMethod:@"post"];
    
    
        //将图片对象转换成NSData数据
        NSData *data=UIImagePNGRepresentation(image);
        //第一个参数为准备上传图片的data数据
        //第二为上传到服务器后,该图片的名称
        //第三个参数为图片类型
        //第四个参数为服务器接收图片的key
        [_request setData:data withFileName:@"a.png" andContentType:@"image/png" forKey:@"attach"];
        //开始上传图片
        [_request startAsynchronous];
        
    }
    
    
    //登录调用
    - (IBAction)loginBtnClick:(id)sender {
        //
        NSURL *url=[NSURL URLWithString:@"http://10.0.8.8/sns/my/login.php"];
        _request=[[ASIFormDataRequest alloc]initWithURL:url];
        [_request setRequestMethod:@"post"];
        [_request addPostValue:self.nameTextField.text forKey:@"username"];
        [_request addPostValue:self.pwdTextField.text forKey:@"password"];
        _request.delegate=self;
        [_request startAsynchronous];
        
        
        
        
        
    }
    - (void)requestFinished:(ASIHTTPRequest *)request
    {
        //相应成功调用
        NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",dict);
    }
    - (void)requestFailed:(ASIHTTPRequest *)request
    {
        NSLog(@"数据失败");
    }
    
    
    
    //选择相册中图片时调用
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        NSLog(@"abc");
        
        //获得选中的图片
        image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
        self.imgView.image=image;
        [_pickerController dismissViewControllerAnimated:YES completion:^{
            
        }];
        
        
    }
    @end
    #import <UIKit/UIKit.h>
    #import "AFNetworking.h"
    #import "GDataXMLNode.h"
    @interface ZYKAppDelegate : UIResponder <UIApplicationDelegate>
    {
        AFHTTPRequestOperationManager *_manager;
        GDataXMLDocument *_doc;
    }
    @property (strong, nonatomic) UIWindow *window;
    
    @end
    
    
    
    #import "ZYKAppDelegate.h"
    
    @implementation ZYKAppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        _manager=[AFHTTPRequestOperationManager manager];
        //关闭AF自动解析功能
        _manager.responseSerializer=[AFHTTPResponseSerializer serializer];
        //加载数据
        [_manager GET:@"http://10.0.8.8/sns/my/user_list.php?page=1&number=5&format=xml" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            //如果相应成功,加载数据
            //通过GData框架,手动解析加载过来的数据
            _doc =[[GDataXMLDocument alloc]initWithData:responseObject options:0 error:nil];
            GDataXMLElement *rootElement=[_doc rootElement];
            NSLog(@"%@",rootElement);
            
            
            
            
            
            
            
            
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            
            
            
        }];
        
        
        
        
        
        
        
        
        
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }
  • 相关阅读:
    atitit.组件化事件化的编程模型--服务端控件(1)---------服务端控件与标签的关系
    atitit. 浏览器插件 控件 applet 的部署,签名总结 浏览器 插件 控件 的签名安全机制o9o
    Atitit. 解压缩zip文件 的实现最佳实践 java c# .net php
    atitit. applet 浏览器插件 控件 的环境,开发,提示总结o9o
    Atitit..文件上传组件选型and最佳实践总结(3)----断点续传控件的实现
    Atitit..文件上传组件选型and最佳实践总结(2)----断点续传
    Atitit.guice3 ioc 最佳实践 o9o
    Atitit. C# java 的api 目录封装结构映射总结
    atitit. 统计功能框架的最佳实践(1)---- on hibernate criteria
    Atitit.Hibernate中Criteria 使用总结and 关联查询 and 按照子对象查询 o9o
  • 原文地址:https://www.cnblogs.com/y16879w/p/4490848.html
Copyright © 2011-2022 走看看