]> mj.ucw.cz Git - libucw.git/blob - sherlock/xml/dtd.h
522274f2b25fb319b42248f76767d0ccf1aea3fd
[libucw.git] / sherlock / xml / dtd.h
1 /*
2  *      Sherlock Library -- A simple XML parser
3  *
4  *      (c) 2007 Pavel Charvat <pchar@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _SHERLOCK_XML_DTD_H
11 #define _SHERLOCK_XML_DTD_H
12
13 #include "sherlock/xml/xml.h"
14
15 struct xml_dtd {
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 */
29 };
30
31 struct xml_ext_id {
32   char *system_id;
33   char *public_id;
34 };
35
36 /* Notations */
37
38 enum xml_dtd_notn_flags {
39   XML_DTD_NOTN_DECLARED = 0x1,          /* The notation has been declared (interbal usage) */
40 };
41
42 struct xml_dtd_notn {
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 */
47 };
48
49 /* Entities */
50
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 */
59 };
60
61 struct xml_dtd_ent {
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) */
70 };
71
72 struct xml_dtd_ent *xml_dtd_find_ent(struct xml_context *ctx, char *name);
73
74 /* Elements */
75
76 enum xml_dtd_elem_flags {
77   XML_DTD_ELEM_DECLARED = 0x1,          /* The element has been declared (internal usage) */
78 };
79
80 enum xml_dtd_elem_type {
81   XML_DTD_ELEM_EMPTY,
82   XML_DTD_ELEM_ANY,
83   XML_DTD_ELEM_MIXED,
84   XML_DTD_ELEM_CHILDREN,
85 };
86
87 struct xml_dtd_elem {
88   snode n;
89   uns flags;
90   uns type;
91   char *name;
92   struct xml_dtd_elem_node *node;
93 };
94
95 struct xml_dtd_elem_node {
96   snode n;
97   struct xml_dtd_elem_node *parent;
98   struct xml_dtd_elem *elem;
99   slist sons;
100   uns type;
101   uns occur;
102 };
103
104 enum xml_dtd_elem_node_type {
105   XML_DTD_ELEM_PCDATA,
106   XML_DTD_ELEM_SEQ,
107   XML_DTD_ELEM_OR,
108 };
109
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,
115 };
116
117 struct xml_dtd_elem *xml_dtd_find_elem(struct xml_context *ctx, char *name);
118
119 /* Attributes */
120
121 enum xml_dtd_attribute_default {
122   XML_ATTR_NONE,
123   XML_ATTR_REQUIRED,
124   XML_ATTR_IMPLIED,
125   XML_ATTR_FIXED,
126 };
127
128 enum xml_dtd_attribute_type {
129   XML_ATTR_CDATA,
130   XML_ATTR_ID,
131   XML_ATTR_IDREF,
132   XML_ATTR_IDREFS,
133   XML_ATTR_ENTITY,
134   XML_ATTR_ENTITIES,
135   XML_ATTR_NMTOKEN,
136   XML_ATTR_NMTOKENS,
137   XML_ATTR_ENUM,
138   XML_ATTR_NOTATION,
139 };
140
141 struct xml_dtd_attr {
142   char *name;
143   struct xml_dtd_elem *elem;
144   enum xml_dtd_attribute_type type;
145   enum xml_dtd_attribute_default default_mode;
146   char *default_value;
147 };
148
149 struct xml_dtd_eval {
150   struct xml_dtd_attr *attr;
151   char *val;
152 };
153
154 struct xml_dtd_enotn {
155   struct xml_dtd_attr *attr;
156   struct xml_dtd_notn *notn;
157 };
158
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);
162
163 struct xml_dtd_attr *xml_dtd_find_attr(struct xml_context *ctx, struct xml_dtd_elem *elem, char *name);
164
165 #endif