]> wimlib.net Git - wimlib/blob - include/wimlib/xmlproc.h
mount_image.c: add fallback definitions of RENAME_* constants
[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 void
42 xml_add_child(struct xml_node *parent, struct xml_node *child);
43
44 void
45 xml_unlink_node(struct xml_node *node);
46
47 void
48 xml_free_node(struct xml_node *node);
49
50 const tchar *
51 xml_element_get_text(const struct xml_node *element);
52
53 int
54 xml_element_set_text(struct xml_node *element, const tchar *text);
55
56 struct xml_node *
57 xml_get_attrib(const struct xml_node *element, const tchar *name);
58
59 int
60 xml_set_attrib(struct xml_node *element, const tchar *name, const tchar *value);
61
62 void
63 xml_replace_child(struct xml_node *parent, struct xml_node *replacement);
64
65 struct xml_node *
66 xml_clone_tree(struct xml_node *orig);
67
68 bool
69 xml_legal_path(const tchar *name);
70
71 bool
72 xml_legal_value(const tchar *value);
73
74 /*****************************************************************************/
75
76 int
77 xml_parse_document(const tchar *raw_doc, struct xml_node **doc_ret);
78
79 /*****************************************************************************/
80
81 struct xml_out_buf {
82         tchar *buf;
83         size_t count;
84         size_t capacity;
85         bool oom;
86 };
87
88 int
89 xml_write_document(struct xml_node *doc, struct xml_out_buf *buf);
90
91 #endif /* _WIMLIB_XMLPROC_H */