]> wimlib.net Git - wimlib/blob - include/wimlib/xmlproc.h
374d27e2cc2c4667132964d655679e9f651a6688
[wimlib] / include / wimlib / xmlproc.h
1 #ifndef _WIMLIB_XMLPROC_H
2 #define _WIMLIB_XMLPROC_H
3
4 #include "wimlib/list.h"
5 #include "wimlib/types.h"
6
7 /*****************************************************************************/
8
9 enum xml_node_type {
10         XML_ELEMENT_NODE,
11         XML_TEXT_NODE,
12         XML_ATTRIBUTE_NODE,
13 };
14
15 struct xml_node {
16         enum xml_node_type type;        /* type of node */
17         tchar *name;                    /* name of ELEMENT or ATTRIBUTE */
18         tchar *value;                   /* value of TEXT or ATTRIBUTE */
19         struct xml_node *parent;        /* parent, or NULL if none */
20         struct list_head children;      /* children; only used for ELEMENT */
21         struct list_head sibling_link;
22 };
23
24 /* Iterate through the children of an xml_node.  Does nothing if passed NULL. */
25 #define xml_node_for_each_child(parent, child) \
26         if (parent) list_for_each_entry(child, &(parent)->children, sibling_link)
27
28 static inline bool
29 xml_node_is_element(const struct xml_node *node, const tchar *name)
30 {
31         return node->type == XML_ELEMENT_NODE && !tstrcmp(node->name, name);
32 }
33
34 struct xml_node *
35 xml_new_element(struct xml_node *parent, const tchar *name);
36
37 struct xml_node *
38 xml_new_element_with_text(struct xml_node *parent, const tchar *name,
39                           const tchar *text);
40
41 struct xml_node *
42 xml_new_attrib(struct xml_node *parent, const tchar *name, const tchar *value);
43
44 void
45 xml_add_child(struct xml_node *parent, struct xml_node *child);
46
47 void
48 xml_unlink_node(struct xml_node *node);
49
50 void
51 xml_free_node(struct xml_node *node);
52
53 const tchar *
54 xml_element_get_text(const struct xml_node *element);
55
56 int
57 xml_element_set_text(struct xml_node *element, const tchar *text);
58
59 struct xml_node *
60 xml_get_attrib(const struct xml_node *element, const tchar *name);
61
62 int
63 xml_set_attrib(struct xml_node *element, const tchar *name, const tchar *value);
64
65 void
66 xml_replace_child(struct xml_node *parent, struct xml_node *replacement);
67
68 struct xml_node *
69 xml_clone_tree(struct xml_node *orig);
70
71 bool
72 xml_legal_name(const tchar *name);
73
74 bool
75 xml_legal_value(const tchar *value);
76
77 /*****************************************************************************/
78
79 int
80 xml_parse_document(const tchar *p, struct xml_node **doc_ret);
81
82 /*****************************************************************************/
83
84 struct xml_out_buf {
85         tchar *buf;
86         size_t count;
87         size_t capacity;
88         bool oom;
89 };
90
91 int
92 xml_write_document(struct xml_node *doc, struct xml_out_buf *buf);
93
94 #endif /* _WIMLIB_XMLPROC_H */