-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
92 lines (78 loc) · 2.22 KB
/
example.c
File metadata and controls
92 lines (78 loc) · 2.22 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <xemil.h>
#define INDENT 2
void recursive(xemil_t* handle, xl_node_t* node, int indent) {
int i;
xl_node_t* n;
for(i = 0; i < indent; i++) printf(" ");
if(node->name != NULL && (node->type == XL_NODE_NODE || node->type == XL_NODE_PROCESS)) {
xl_attribute_t* a;
printf("<%s%s", node->type == XL_NODE_PROCESS ? "?" : "", node->name);
a = node->first_attribute;
while(a != NULL) {
if(a->value == NULL) {
printf(" %s", a->key);
} else {
printf(" %s=\"%s\"", a->key, a->value);
}
a = a->next;
}
printf("%s%s>\n", node->type == XL_NODE_PROCESS ? "?" : "", (node->first_child == NULL && node->text == NULL) ? " /" : "");
if(node->text != NULL && !handle->param.new_text) {
for(i = 0; i < indent + INDENT; i++) printf(" ");
printf("%s\n", node->text);
}
} else if(node->text != NULL && node->type == XL_NODE_COMMENT) {
printf("<!--%s-->\n", node->text);
} else if(node->text != NULL && node->type == XL_NODE_TEXT) {
printf("%s\n", node->text);
}
n = node->first_child;
while(n != NULL) {
recursive(handle, n, indent + INDENT);
n = n->next;
}
if(node->name != NULL && node->type == XL_NODE_NODE && !(node->first_child == NULL && node->text == NULL && !handle->param.new_text)) {
for(i = 0; i < indent; i++) printf(" ");
printf("</%s>\n", node->name);
}
}
int main(int argc, char** argv) {
int i;
xl_node_t* n;
for(i = 1; i < argc; i++) {
xemil_t* h = xl_open_file(argv[i]);
if(h != NULL) {
h->param.new_text = 1;
h->param.do_xinclude = 1;
printf("%s:\n", argv[i]);
if(xl_parse(h)) {
xl_node_t** r;
n = h->pre;
if(n != NULL) {
while(n != NULL) {
/* recursive(h, n, INDENT); */
n = n->next;
}
}
/* if(h->root != NULL) recursive(h, h->root, INDENT); */
r = xl_xpointer(h->root, "element(/book/title)");
/* check if book.title dosent exist to prevent SEGFAULT */
if(r != NULL) {
int j;
for(j = 0; r[j] != NULL; j++) {
recursive(h, r[j], INDENT);
}
free(r);
} else {
printf("book.title not found in %s\n", argv[i]);
}
recursive(h, h->root, 0);
} else {
int j;
for(j = 0; j < INDENT; j++) printf(" ");
printf("Parse error\n");
}
xl_close(h);
}
}
}