2 * UCW Library -- A simple XML parser
4 * (c) 2007--2008 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
10 #ifndef _UCW_XML_DTD_H
11 #define _UCW_XML_DTD_H
13 #include <ucw-xml/xml.h>
15 #ifdef CONFIG_UCW_CLEAN_ABI
16 #define xml_dtd_cleanup ucw_xml_dtd_cleanup
17 #define xml_dtd_find_attr ucw_xml_dtd_find_attr
18 #define xml_dtd_find_elem ucw_xml_dtd_find_elem
19 #define xml_dtd_find_entity ucw_xml_dtd_find_entity
20 #define xml_dtd_find_notn ucw_xml_dtd_find_notn
21 #define xml_dtd_finish ucw_xml_dtd_finish
22 #define xml_dtd_init ucw_xml_dtd_init
26 struct mempool *pool; /* Memory pool where to allocate DTD */
27 slist ents; /* Link list of general entities */
28 slist pents; /* Link list of parameter entities */
29 slist notns; /* Link list of notations */
30 slist elems; /* Link list of elements */
31 void *tab_ents; /* Hash table of general entities */
32 void *tab_pents; /* Hash table of parameter entities */
33 void *tab_notns; /* Hash table of notations */
34 void *tab_elems; /* Hash table of elements */
35 void *tab_enodes; /* Hash table of element sons */
36 void *tab_attrs; /* Hash table of element attributes */
37 void *tab_evals; /* Hash table of enumerated attribute values */
38 void *tab_enotns; /* hash table of enumerated attribute notations */
43 enum xml_dtd_notn_flags {
44 XML_DTD_NOTN_DECLARED = 0x1, /* The notation has been declared (internal usage) */
48 snode n; /* Node in xml_dtd.notns */
49 uint flags; /* XML_DTD_NOTN_x */
50 char *name; /* Notation name */
51 char *system_id; /* External ID */
53 void *user; /* User-defined */
56 struct xml_dtd_notn *xml_dtd_find_notn(struct xml_context *ctx, char *name);
60 enum xml_dtd_entity_flags {
61 XML_DTD_ENTITY_DECLARED = 0x1, /* The entity has been declared (internal usage) */
62 XML_DTD_ENTITY_VISITED = 0x2, /* Cycle detection (internal usage) */
63 XML_DTD_ENTITY_PARAMETER = 0x4, /* Parameter entity, general otherwise */
64 XML_DTD_ENTITY_EXTERNAL = 0x8, /* External entity, internal otherwise */
65 XML_DTD_ENTITY_UNPARSED = 0x10, /* Unparsed entity, parsed otherwise */
66 XML_DTD_ENTITY_TRIVIAL = 0x20, /* Replacement text is a sequence of characters and character references */
69 struct xml_dtd_entity {
70 snode n; /* Node in xml_dtd.[gp]ents */
71 uint flags; /* XML_DTD_ENT_x */
72 char *name; /* Entity name */
73 char *text; /* Replacement text / expanded replacement text (XML_DTD_ENT_TRIVIAL) */
74 uint len; /* Text length */
75 char *system_id; /* External ID */
77 struct xml_dtd_notn *notn; /* Notation (XML_DTD_ENT_UNPARSED only) */
78 void *user; /* User-defined */
81 struct xml_dtd_entity *xml_dtd_find_entity(struct xml_context *ctx, char *name);
85 enum xml_dtd_elem_flags {
86 XML_DTD_ELEM_DECLARED = 0x1, /* The element has been declared (internal usage) */
89 enum xml_dtd_elem_type {
93 XML_DTD_ELEM_CHILDREN,
101 struct xml_dtd_elem_node *node;
103 void *user; /* User-defined */
106 struct xml_dtd_elem_node {
108 struct xml_dtd_elem_node *parent;
109 struct xml_dtd_elem *elem;
113 void *user; /* User-defined */
116 enum xml_dtd_elem_node_type {
122 enum xml_dtd_elem_node_occur {
123 XML_DTD_ELEM_OCCUR_ONCE,
124 XML_DTD_ELEM_OCCUR_OPT,
125 XML_DTD_ELEM_OCCUR_MULT,
126 XML_DTD_ELEM_OCCUR_PLUS,
129 struct xml_dtd_elem *xml_dtd_find_elem(struct xml_context *ctx, char *name);
133 enum xml_dtd_attr_default {
140 enum xml_dtd_attr_type {
153 struct xml_dtd_attr {
155 char *name; /* Attribute name */
156 struct xml_dtd_elem *elem; /* Owner element */
157 uint type; /* See enum xml_dtd_attr_type */
158 uint default_mode; /* See enum xml_dtd_attr_default */
159 char *default_value; /* The default value defined in DTD (or NULL) */
162 struct xml_dtd_eval {
163 struct xml_dtd_attr *attr;
167 struct xml_dtd_enotn {
168 struct xml_dtd_attr *attr;
169 struct xml_dtd_notn *notn;
172 void xml_dtd_init(struct xml_context *ctx);
173 void xml_dtd_cleanup(struct xml_context *ctx);
174 void xml_dtd_finish(struct xml_context *ctx);
176 struct xml_dtd_attr *xml_dtd_find_attr(struct xml_context *ctx, struct xml_dtd_elem *elem, char *name);