-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.cpp
More file actions
65 lines (55 loc) · 1.15 KB
/
parser.cpp
File metadata and controls
65 lines (55 loc) · 1.15 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "parser.h"
Parser::~Parser(){
}
void Parser::open(char* filename){
if (NULL == filename){
return;
}
_doc = xmlReadFile(filename, "UTF-8", XML_PARSE_RECOVER|XML_PARSE_NOBLANKS);
if (_doc == NULL){
printf ("open %s faild.\n", filename);
return;
}
_root = xmlDocGetRootElement (_doc);
if (_root == NULL){
printf("Error: %s is empty(hasn't root node.\n", filename);
return;
}
return;
}
void Parser::close(){
xmlFreeDoc(_doc);
xmlCleanupParser();
}
xmlNodePtr Parser::root(){
if (NULL == _root){
return NULL;
}
return _root;
}
#ifdef DEBUG
void Parser::dump(){
xmlNodePtr curNode = NULL;
if (NULL == _root){
return;
}
if (xmlHasProp (_root, BAD_CAST "version")){
xmlChar* szAttr = xmlGetProp (_root, BAD_CAST "version");
printf ("version: %s\n root: %s\n", szAttr, _root->name);
}else{
printf ("xml hasn't version info\n");
}
curNode = _root->xmlChildrenNode;
char n = 0;
while (curNode != NULL){
if (curNode->name != BAD_CAST "text"){
printf ("child%d: %s\n", n++, curNode->name);
}
curNode = curNode->next;
}
}
#endif