2 * Sherlock 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 _SHERLOCK_XML_DTD_H
11 #define _SHERLOCK_XML_DTD_H
16 struct mempool *pool; /* Memory pool where to allocate DTD */
17 slist ents; /* Link list of general entities */
18 slist pents; /* Link list of parameter entities */
19 slist notns; /* Link list of notations */
20 slist elems; /* Link list of elements */
21 void *tab_ents; /* Hash table of general entities */
22 void *tab_pents; /* Hash table of parameter entities */
23 void *tab_notns; /* Hash table of notations */
24 void *tab_elems; /* Hash table of elements */
25 void *tab_enodes; /* Hash table of element sons */
26 void *tab_attrs; /* Hash table of element attributes */
27 void *tab_evals; /* Hash table of enumerated attribute values */
28 void *tab_enotns; /* hash table of enumerated attribute notations */
33 enum xml_dtd_notn_flags {
34 XML_DTD_NOTN_DECLARED = 0x1, /* The notation has been declared (internal usage) */
38 snode n; /* Node in xml_dtd.notns */
39 uint flags; /* XML_DTD_NOTN_x */
40 char *name; /* Notation name */
41 char *system_id; /* External ID */
43 void *user; /* User-defined */
46 struct xml_dtd_notn *xml_dtd_find_notn(struct xml_context *ctx, char *name);
50 enum xml_dtd_entity_flags {
51 XML_DTD_ENTITY_DECLARED = 0x1, /* The entity has been declared (internal usage) */
52 XML_DTD_ENTITY_VISITED = 0x2, /* Cycle detection (internal usage) */
53 XML_DTD_ENTITY_PARAMETER = 0x4, /* Parameter entity, general otherwise */
54 XML_DTD_ENTITY_EXTERNAL = 0x8, /* External entity, internal otherwise */
55 XML_DTD_ENTITY_UNPARSED = 0x10, /* Unparsed entity, parsed otherwise */
56 XML_DTD_ENTITY_TRIVIAL = 0x20, /* Replacement text is a sequence of characters and character references */
59 struct xml_dtd_entity {
60 snode n; /* Node in xml_dtd.[gp]ents */
61 uint flags; /* XML_DTD_ENT_x */
62 char *name; /* Entity name */
63 char *text; /* Replacement text / expanded replacement text (XML_DTD_ENT_TRIVIAL) */
64 uint len; /* Text length */
65 char *system_id; /* External ID */
67 struct xml_dtd_notn *notn; /* Notation (XML_DTD_ENT_UNPARSED only) */
68 void *user; /* User-defined */
71 struct xml_dtd_entity *xml_dtd_find_entity(struct xml_context *ctx, char *name);
75 enum xml_dtd_elem_flags {
76 XML_DTD_ELEM_DECLARED = 0x1, /* The element has been declared (internal usage) */
79 enum xml_dtd_elem_type {
83 XML_DTD_ELEM_CHILDREN,
91 struct xml_dtd_elem_node *node;
93 void *user; /* User-defined */
96 struct xml_dtd_elem_node {
98 struct xml_dtd_elem_node *parent;
99 struct xml_dtd_elem *elem;
103 void *user; /* User-defined */
106 enum xml_dtd_elem_node_type {
112 enum xml_dtd_elem_node_occur {
113 XML_DTD_ELEM_OCCUR_ONCE,
114 XML_DTD_ELEM_OCCUR_OPT,
115 XML_DTD_ELEM_OCCUR_MULT,
116 XML_DTD_ELEM_OCCUR_PLUS,
119 struct xml_dtd_elem *xml_dtd_find_elem(struct xml_context *ctx, char *name);
123 enum xml_dtd_attr_default {
130 enum xml_dtd_attr_type {
143 struct xml_dtd_attr {
145 char *name; /* Attribute name */
146 struct xml_dtd_elem *elem; /* Owner element */
147 uint type; /* See enum xml_dtd_attr_type */
148 uint default_mode; /* See enum xml_dtd_attr_default */
149 char *default_value; /* The default value defined in DTD (or NULL) */
152 struct xml_dtd_eval {
153 struct xml_dtd_attr *attr;
157 struct xml_dtd_enotn {
158 struct xml_dtd_attr *attr;
159 struct xml_dtd_notn *notn;
162 void xml_dtd_init(struct xml_context *ctx);
163 void xml_dtd_cleanup(struct xml_context *ctx);
164 void xml_dtd_finish(struct xml_context *ctx);
166 struct xml_dtd_attr *xml_dtd_find_attr(struct xml_context *ctx, struct xml_dtd_elem *elem, char *name);