iOS网络篇---使用NSSession 实现获取XML

来源:互联网 发布:vba 网页数据抓取 编辑:程序博客网 时间:2024/06/16 05:42

- (void)xmlDataTaskGet

{

    NSString *strUrl=@"http://192.168.0.124:8080/WYServer/video?type=XML";

   NSURLRequest *request=[NSURLRequestrequestWithURL:[NSURLURLWithString:strUrl]];

    NSURLSession *session=[NSURLSessionsharedSession];

   NSURLSessionDataTask *dataTask=[session dataTaskWithRequest:request completionHandler:^(NSData *data,NSURLResponse *response, NSError *error) {

        GDataXMLDocument *doc=[[GDataXMLDocumentalloc] initWithData:data options:0error:nil];

       GDataXMLElement *root=doc.rootElement;

       for (GDataXMLElement *ein root.children) {

            NSLog(@"%@  %@  %@  %@  %@  ",

                  [e attributeForName:@"id"].stringValue,

                  [e attributeForName:@"name"].stringValue,

                  [e attributeForName:@"length"].stringValue,

                  [e attributeForName:@"image"].stringValue,

                  [e attributeForName:@"url"].stringValue

                  );

        }

        

    }];

    [dataTaskresume];

    

    

}


0 0
原创粉丝点击