//
//  jobXML.m
//  Open
//
//  Created by 看看智能 on 2018/1/22.
//  Copyright © 2018年 黄江涛 . All rights reserved.
//

#import "jobXML.h"
static int dateNumber;

@implementation jobXML
-(NSArray *)parseWithPath:(NSString *)path
{
    dateNumber =1;
    self.movies = [NSMutableArray array];
    self.justChange = [NSMutableArray array];
    NSData *data = [NSData dataWithContentsOfFile:path];
    //创建xml解析类
    NSXMLParser *parser = [[NSXMLParser alloc]initWithData:data];
    parser.delegate = self;
    //开始解析
    [parser parse];
    return self.movies;
    
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary<NSString *,NSString *> *)attributeDict{

        if ([self.xmlName isEqualToString:@"workTypeSelection"]) {
            if ([elementName isEqualToString:@"string-array"]) {
                workTypeSelectionNSObject *model  = [workTypeSelectionNSObject new];
                model.nameJob =attributeDict[@"name"];
                model.WorkTypeId = dateNumber;
                dateNumber ++;
                [self.movies addObject:model];
                
            }
            
            
        }else{
            if ([elementName isEqualToString:@"string-array"]) {
                PersonJob *model  = [PersonJob new];
                model.nameJob =attributeDict[@"name"];
                model.jobID = dateNumber;
                dateNumber ++;
                [self.movies addObject:model];
                
            }
            
        }
    
    
 

}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
 self.currentString = string;
 NSLog(@"发现文本：%@",string);
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

    
  
    
    
    if ([self.xmlName isEqualToString:@"workTypeSelection"]) {
        workTypeSelectionNSObject *m = [self.movies lastObject];
        if ([elementName isEqualToString:@"item"]) {
            [self.justChange addObject:self.currentString];
        }
        if ([elementName isEqualToString:@"string-array"]) {
            m.politicalStatus = self.justChange;
            [self.justChange removeAllObjects];
        }
    }else{
        PersonJob *m = [self.movies lastObject];
        if ([elementName isEqualToString:@"item"]) {
            [self.justChange addObject:self.currentString];
        }
        if ([elementName isEqualToString:@"string-array"]) {
            m.politicalStatus = self.justChange;
            [self.justChange removeAllObjects];
        }
    }
    
    

}


@end
