1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| //open xml file
FILE* fp = fopen(fileName,"r");
//create mxml tree head node
mxml_node_t* tree = mxmlLoadFile(NULL,fp,MXML_NO_CALLBACK);
//build head node:proto_meta_dump
//第一层
mxml_node_t* proto = NULL;
//第二层
mxml_node_t* class = NULL;
mxml_node_t* suit = NULL;
mxml_node_t* desc = NULL;
mxml_node_t* name = NULL;
//第三层
mxml_node_t* meta_data = NULL;
mxml_node_t* dump_on = NULL;
mxml_node_t* dump_format = NULL;
mxml_node_t* dump_name = NULL;
//遍历第一层proto,mxmlFindElement函数:寻找下一个proto节点
for(proto = mxmlFindElement(tree,tree,"proto","name",NULL,MXML_DESCEND);proto!=NULL;proto = mxmlFindElement(proto,tree,"proto","name",NULL,MXML_DESCEND)){
class = mxmlFindElement(proto,tree,"proto-class",NULL,NULL,MXML_DESCEND);
suit = mxmlFindElement(proto,tree,"proto-suit",NULL,NULL,MXML_DESCEND);
desc = mxmlFindElement(proto,tree,"proto-desc",NULL,NULL,MXML_DESCEND);
name = mxmlFindElement(proto,tree,"dump-name",NULL,NULL,MXML_DESCEND);
//拿到第一层数据
printf("|proto:%s\n",mxmlElementGetAttr(proto,"name"));
printf(" |----class:%s\n",mxmlGetText(class,NULL));
printf(" |----suit:%s\n",mxmlGetText(suit,NULL));
printf(" |----desc:%s\n",mxmlGetText(desc,NULL));
printf(" |----name:%s\n",mxmlGetText(name,NULL));
//遍历第二层meta-data
for(meta_data = mxmlFindElement(proto,proto,"meta-data","name",NULL,MXML_DESCEND);meta_data!=NULL;meta_data = mxmlFindElement(meta_data,proto,"meta-data","name",NULL,MXML_DESCEND)){
//拿到第二层数据
dump_on = mxmlFindElement(meta_data,proto,"dump-on",NULL,NULL,MXML_DESCEND);
dump_id = mxmlFindElement(meta_data,proto,"dump-id",NULL,NULL,MXML_DESCEND);
dump_format = mxmlFindElement(meta_data,proto,"dump-format",NULL,NULL,MXML_DESCEND);
dump_name = mxmlFindElement(meta_data,proto,"dump-name",NULL,NULL,MXML_DESCEND);
printf(...,mxmlGetText(...));
...
}
}
mxmlDelete(tree);
fclose(fp);
|