]> mj.ucw.cz Git - libucw.git/blob - xml/dtd.h
Renamed shxml/* to xml/*.
[libucw.git] / xml / dtd.h
1 /*
2  *      Sherlock Library -- A simple XML parser
3  *
4  *      (c) 2007--2008 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 <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 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 */
29 };
30
31 /* Notations */
32
33 enum xml_dtd_notn_flags {
34   XML_DTD_NOTN_DECLARED = 0x1,          /* The notation has been declared (internal usage) */
35 };
36
37 struct xml_dtd_notn {
38   snode n;                              /* Node in xml_dtd.notns */
39   uns flags;                            /* XML_DTD_NOTN_x */
40   char *name;                           /* Notation name */
41   char *system_id;                      /* External ID */
42   char *public_id;
43   void *user;                           /* User-defined */
44 };
45
46 struct xml_dtd_notn *xml_dtd_find_notn(struct xml_context *ctx, char *name);
47
48 /* Entities */
49
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 */
57 };
58
59 struct xml_dtd_entity {
60   snode n;                              /* Node in xml_dtd.[gp]ents */
61   uns flags;                            /* XML_DTD_ENT_x */
62   char *name;                           /* Entity name */
63   char *text;                           /* Replacement text / expanded replacement text (XML_DTD_ENT_TRIVIAL) */
64   uns len;                              /* Text length */
65   char *system_id;                      /* External ID */
66   char *public_id;
67   struct xml_dtd_notn *notn;            /* Notation (XML_DTD_ENT_UNPARSED only) */
68   void *user;                           /* User-defined */
69 };
70
71 struct xml_dtd_entity *xml_dtd_find_entity(struct xml_context *ctx, char *name);
72
73 /* Elements */
74
75 enum xml_dtd_elem_flags {
76   XML_DTD_ELEM_DECLARED = 0x1,          /* The element has been declared (internal usage) */
77 };
78
79 enum xml_dtd_elem_type {
80   XML_DTD_ELEM_EMPTY,
81   XML_DTD_ELEM_ANY,
82   XML_DTD_ELEM_MIXED,
83   XML_DTD_ELEM_CHILDREN,
84 };
85
86 struct xml_dtd_elem {
87   snode n;
88   uns flags;
89   uns type;
90   char *name;
91   struct xml_dtd_elem_node *node;
92   slist attrs;
93   void *user;                           /* User-defined */
94 };
95
96 struct xml_dtd_elem_node {
97   snode n;
98   struct xml_dtd_elem_node *parent;
99   struct xml_dtd_elem *elem;
100   slist sons;
101   uns type;
102   uns occur;
103   void *user;                           /* User-defined */
104 };
105
106 enum xml_dtd_elem_node_type {
107   XML_DTD_ELEM_PCDATA,
108   XML_DTD_ELEM_SEQ,
109   XML_DTD_ELEM_OR,
110 };
111
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,
117 };
118
119 struct xml_dtd_elem *xml_dtd_find_elem(struct xml_context *ctx, char *name);
120
121 /* Attributes */
122
123 enum xml_dtd_attr_default {
124   XML_ATTR_NONE,
125   XML_ATTR_REQUIRED,
126   XML_ATTR_IMPLIED,
127   XML_ATTR_FIXED,
128 };
129
130 enum xml_dtd_attr_type {
131   XML_ATTR_CDATA,
132   XML_ATTR_ID,
133   XML_ATTR_IDREF,
134   XML_ATTR_IDREFS,
135   XML_ATTR_ENTITY,
136   XML_ATTR_ENTITIES,
137   XML_ATTR_NMTOKEN,
138   XML_ATTR_NMTOKENS,
139   XML_ATTR_ENUM,
140   XML_ATTR_NOTATION,
141 };
142
143 struct xml_dtd_attr {
144   snode n;
145   char *name;                           /* Attribute name */
146   struct xml_dtd_elem *elem;            /* Owner element */
147   uns type;                             /* See enum xml_dtd_attr_type */
148   uns default_mode;                     /* See enum xml_dtd_attr_default */
149   char *default_value;                  /* The default value defined in DTD (or NULL) */
150 };
151
152 struct xml_dtd_eval {
153   struct xml_dtd_attr *attr;
154   char *val;
155 };
156
157 struct xml_dtd_enotn {
158   struct xml_dtd_attr *attr;
159   struct xml_dtd_notn *notn;
160 };
161
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);
165
166 struct xml_dtd_attr *xml_dtd_find_attr(struct xml_context *ctx, struct xml_dtd_elem *elem, char *name);
167
168 #endif