需要从GitHub上下载GdataxML_Node文件,也可以从我上传的资料中下载。
NSBundle *bundle = [NSBundlemainBundle];
NSString *path = [bundle pathForResource:@"StudentInfo_XML" ofType:@"txt"];
//1KB = 1024B 1MB = 1024KB 1GB = 1024MB 1TB = 2^10 GB
//1PB = 2^10 TB 1EB = 2^10 PB
//32位操作系统最大容量:X32 = 2^32B = 4GB .
//2.根据文件路径来创建data对象-->data可以存储8EB的容量,最终转换成二进制。
//计算机就是一种电路,只有开和关两种逻辑电路。0-1
NSData *data = [NSDatadataWithContentsOfFile:path];
//3.创建解析对象
GdataxMLDocument *document = [[GdataxMLDocumentalloc]initWithData:dataoptions:0 error:nil];
//4.获取根节点
GdataxMLElement *rootElement = [document rootElement];
//创建数组
_array = [[NSMutableArrayalloc]initWithCapacity:6];
//5.开始解析
for (GdataxMLElement *subElementin rootElement.children) {
Student *student = [Studentnew];
for (GdataxMLElement *sunElementin subElement.children) {
[studentsetValue:sunElement.stringValueforKey:sunElement.name];
}
[_arrayaddObject:student];
}
//6.校验一下
for (Student *studentin _array) {
NSLog(@"%@",student);
}
原文链接:https://www.f2er.com/xml/296062.html