Skip to content

Commit f1cc013

Browse files
committed
Add experimental XML parser/writer
1 parent 41c8fb8 commit f1cc013

File tree

2 files changed

+1006
-0
lines changed

2 files changed

+1006
-0
lines changed

src/includes/xml.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef INCLUDE_XML_H
2+
#define INCLUDE_XML_H
3+
4+
#include <stddef.h>
5+
6+
typedef enum {
7+
XML_ELEM_TAG,
8+
XML_ELEM_EMPTYTAG,
9+
XML_ELEM_XMLDECL,
10+
XML_ELEM_DECL,
11+
XML_ELEM_COMMENT,
12+
XML_ELEM_TEXT,
13+
XML_ELEM_ROOT,
14+
} xml_elem_type_t;
15+
16+
struct xml_attr_t {
17+
char *key;
18+
char *value;
19+
};
20+
21+
struct xml_elem_t {
22+
xml_elem_type_t type;
23+
24+
char *name;
25+
26+
struct xml_elem_t **child_elem_arr;
27+
size_t child_elem_count;
28+
29+
struct xml_attr_t **attr_arr;
30+
size_t attr_count;
31+
32+
char *text;
33+
};
34+
35+
int xml_create(struct xml_elem_t **doc);
36+
int xml_create_from_file(struct xml_elem_t **doc, const char *filepath);
37+
int xml_create_from_string(struct xml_elem_t **doc, const char *buf);
38+
void xml_destroy(struct xml_elem_t *doc);
39+
int xml_to_file(struct xml_elem_t *doc, const char *filepath);
40+
int xml_to_string(struct xml_elem_t *doc, char **xmlstr);
41+
42+
int xml_elem_create(struct xml_elem_t **elem, xml_elem_type_t type);
43+
int xml_elem_attach(struct xml_elem_t *parent, struct xml_elem_t *elem);
44+
int xml_elem_create_and_attach(struct xml_elem_t *parent, struct xml_elem_t **elem, xml_elem_type_t type);
45+
void xml_elem_destroy(struct xml_elem_t *elem);
46+
int xml_elem_detach(struct xml_elem_t *parent, struct xml_elem_t *elem);
47+
int xml_elem_destroy_and_detach(struct xml_elem_t *parent, struct xml_elem_t *elem);
48+
int xml_elem_copy(const struct xml_elem_t *src, struct xml_elem_t **dst);
49+
50+
int xml_attr_set(struct xml_elem_t *elem, const char *key, const char *value);
51+
int xml_attr_clear(struct xml_elem_t *elem, const char *key);
52+
53+
#endif //INCLUDE_XML_H

0 commit comments

Comments
 (0)