ios xml解析

来源:互联网 发布:金蝶erp源码下载 编辑:程序博客网 时间:2024/05/20 07:59

ios xml解析:

#import "XmlParse.h"#import "TBXML.h"#import "City.h"@implementation XmlParse+(NSMutableArray *)parseMenusByPath:(NSString *)path{    NSMutableArray *citys = [NSMutableArray array];    NSData *data = [NSData dataWithContentsOfFile:path];    TBXML *tbxml = [[TBXML alloc]initWithXMLData:data error:nil];        TBXMLElement *dataEle = tbxml.rootXMLElement;    TBXMLElement *rowEle = [TBXML childElementNamed:@"row" parentElement:dataEle];        //遍历所有的row元素    while (rowEle) {        City *city = [[City alloc]init];        //得到元素属性        TBXMLElement *DEPT_LEV_Ele  = [TBXML childElementNamed:@"LEV"           parentElement:rowEle];        TBXMLElement *DEPT_ID_Ele   = [TBXML childElementNamed:@"DEPT_ID"       parentElement:rowEle];        TBXMLElement *DEPT_CODE_Ele = [TBXML childElementNamed:@"DEPT_CODE"     parentElement:rowEle];        TBXMLElement *DEPT_NAME_Ele = [TBXML childElementNamed:@"DEPT_NAME"     parentElement:rowEle];        TBXMLElement *UPPER_DEPT_ID = [TBXML childElementNamed:@"UPPER_DEPT_ID" parentElement:rowEle];                //得到元素间的文本        city.LEV           = [TBXML textForElement:DEPT_LEV_Ele ];        city.DEPT_ID       = [TBXML textForElement:DEPT_ID_Ele  ];        city.DEPT_CODE     = [TBXML textForElement:DEPT_CODE_Ele];        city.DEPT_NAME     = [TBXML textForElement:DEPT_NAME_Ele];        city.UPPER_DEPT_ID = [TBXML textForElement:UPPER_DEPT_ID];                [citys addObject:city];        rowEle = [TBXML nextSiblingNamed:@"row" searchFromElement:rowEle];    }    return citys;}@end


0 0
原创粉丝点击