2 * Sherlock Library -- A simple XML parser
4 * (c) 2007 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
13 #include "sherlock/xml/xml.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 parapeter 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 */
38 enum xml_dtd_notn_flags {
39 XML_DTD_NOTN_DECLARED = 0x1, /* The notation has been declared (interbal usage) */
43 snode n; /* Node in xml_dtd.notns */
44 uns flags; /* XML_DTD_NOTN_x */
45 char *name; /* Notation name */
46 struct xml_ext_id eid; /* External id */
51 enum xml_dtd_ent_flags {
52 XML_DTD_ENT_DECLARED = 0x1, /* The entity has been declared (internal usage) */
53 XML_DTD_ENT_VISITED = 0x2, /* Cycle detection (internal usage) */
54 XML_DTD_ENT_PARAMETER = 0x4, /* Parameter entity, general otherwise */
55 XML_DTD_ENT_EXTERNAL = 0x8, /* External entity, internal otherwise */
56 XML_DTD_ENT_UNPARSED = 0x10, /* Unparsed entity, parsed otherwise */
57 XML_DTD_ENT_TRIVIAL_STR = 0x20, /* Replacement text is a sequence of characters and character references */
58 XML_DTD_ENT_TRIVIAL_UNI = 0x40, /* Replacement text is a single Unicode character */
62 snode n; /* Node in xml_dtd.[gp]ents */
63 uns flags; /* XML_DTD_ENT_x */
64 char *name; /* Entity name */
65 char *text; /* Replacement text / expanded replacement text (XML_DTD_ENT_TRIVIAL) */
66 uns len; /* Text length */
67 uns uni; /* Unicode value */
68 struct xml_ext_id eid; /* External ID */
69 struct xml_dtd_notn *notn; /* Notation (XML_DTD_ENT_UNPARSED only) */
72 struct xml_dtd_ent *xml_dtd_find_ent(struct xml_context *ctx, char *name);
76 enum xml_dtd_elem_flags {
77 XML_DTD_ELEM_DECLARED = 0x1, /* The element has been declared (internal usage) */
80 enum xml_dtd_elem_type {
84 XML_DTD_ELEM_CHILDREN,
92 struct xml_dtd_elem_node *node;
95 struct xml_dtd_elem_node {
97 struct xml_dtd_elem_node *parent;
98 struct xml_dtd_elem *elem;
104 enum xml_dtd_elem_node_type {
110 enum xml_dtd_elem_node_occur {
111 XML_DTD_ELEM_OCCUR_ONCE,
112 XML_DTD_ELEM_OCCUR_OPT,
113 XML_DTD_ELEM_OCCUR_MULT,
114 XML_DTD_ELEM_OCCUR_PLUS,
117 struct xml_dtd_elem *xml_dtd_find_elem(struct xml_context *ctx, char *name);
121 enum xml_dtd_attribute_default {
128 enum xml_dtd_attribute_type {
141 struct xml_dtd_attr {
143 struct xml_dtd_elem *elem;
144 enum xml_dtd_attribute_type type;
145 enum xml_dtd_attribute_default default_mode;
149 struct xml_dtd_eval {
150 struct xml_dtd_attr *attr;
154 struct xml_dtd_enotn {
155 struct xml_dtd_attr *attr;
156 struct xml_dtd_notn *notn;
159 void xml_dtd_init(struct xml_context *ctx);
160 void xml_dtd_cleanup(struct xml_context *ctx);
161 void xml_dtd_finish(struct xml_context *ctx);
163 struct xml_dtd_attr *xml_dtd_find_attr(struct xml_context *ctx, struct xml_dtd_elem *elem, char *name);