-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
51 lines (48 loc) · 1.23 KB
/
example.c
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
#include "cxml.h"
#include <locale.h>
#include <stdio.h>
#include <windows.h>
void print_indent(u32 indent)
{
for (int i = 0; i < indent; i++) {
printf(" ");
}
}
void print_node(cx_node* node, u32 indent)
{
if (node == null) return;
print_indent(indent);
printf("\"%s\" (", cx_to_utf8(node->name));
cx_attr* attr = node->attrs;
while (attr) {
printf("%s=%s", cx_to_utf8(attr->key), cx_to_utf8(attr->value));
attr = attr->next;
}
printf("):\n");
++indent;
if (node->content.len > 0) {
print_indent(indent);
printf("content: %s\n", cx_to_utf8(node->content));
}
if (node->children) {
print_indent(indent);
printf("children: \n");
indent++;
cx_node* cur = node->children;
for (int i = 0; i < node->child_count; i++) {
print_node(cur, indent);
cur = cur->next;
}
--indent;
}
--indent;
}
int main(int argc, char** argv)
{
// to output utf8 on windows
SetConsoleOutputCP(CP_UTF8);
char* buf = null;
cx_doc d = cx_parse_file(buf, false);
cx_node* r = d.root;
print_node(r, 0);
}