]> mj.ucw.cz Git - libucw.git/blob - sherlock/xml/dtd.h
XML: The great reorganization... several improvements in the iface,
[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 = 0x20,           /* Replacement text is a sequence of characters and character references */
58 };
59
60 struct xml_dtd_ent {
61   snode n;                              /* Node in xml_dtd.[gp]ents */
62   uns flags;                            /* XML_DTD_ENT_x */
63   char *name;                           /* Entity name */
64   char *text;                           /* Replacement text / expanded replacement text (XML_DTD_ENT_TRIVIAL) */
65   uns len;                              /* Text length */
66   struct xml_ext_id eid;                /* External ID */
67   struct xml_dtd_notn *notn;            /* Notation (XML_DTD_ENT_UNPARSED only) */
68 };
69
70 struct xml_dtd_ent *xml_dtd_find_ent(struct xml_context *ctx, char *name);
71
72 /* Elements */
73
74 enum xml_dtd_elem_flags {
75   XML_DTD_ELEM_DECLARED = 0x1,          /* The element has been declared (internal usage) */
76 };
77
78 enum xml_dtd_elem_type {
79   XML_DTD_ELEM_EMPTY,
80   XML_DTD_ELEM_ANY,
81   XML_DTD_ELEM_MIXED,
82   XML_DTD_ELEM_CHILDREN,
83 };
84
85 struct xml_dtd_elem {
86   snode n;
87   uns flags;
88   uns type;
89   char *name;
90   struct xml_dtd_elem_node *node;
91 };
92
93 struct xml_dtd_elem_node {
94   snode n;
95   struct xml_dtd_elem_node *parent;
96   struct xml_dtd_elem *elem;
97   slist sons;
98   uns type;
99   uns occur;
100 };
101
102 enum xml_dtd_elem_node_type {
103   XML_DTD_ELEM_PCDATA,
104   XML_DTD_ELEM_SEQ,
105   XML_DTD_ELEM_OR,
106 };
107
108 enum xml_dtd_elem_node_occur {
109   XML_DTD_ELEM_OCCUR_ONCE,
110   XML_DTD_ELEM_OCCUR_OPT,
111   XML_DTD_ELEM_OCCUR_MULT,
112   XML_DTD_ELEM_OCCUR_PLUS,
113 };
114
115 struct xml_dtd_elem *xml_dtd_find_elem(struct xml_context *ctx, char *name);
116
117 /* Attributes */
118
119 enum xml_dtd_attribute_default {
120   XML_ATTR_NONE,
121   XML_ATTR_REQUIRED,
122   XML_ATTR_IMPLIED,
123   XML_ATTR_FIXED,
124 };
125
126 enum xml_dtd_attribute_type {
127   XML_ATTR_CDATA,
128   XML_ATTR_ID,
129   XML_ATTR_IDREF,
130   XML_ATTR_IDREFS,
131   XML_ATTR_ENTITY,
132   XML_ATTR_ENTITIES,
133   XML_ATTR_NMTOKEN,
134   XML_ATTR_NMTOKENS,
135   XML_ATTR_ENUM,
136   XML_ATTR_NOTATION,
137 };
138
139 struct xml_dtd_attr {
140   char *name;
141   struct xml_dtd_elem *elem;
142   enum xml_dtd_attribute_type type;
143   enum xml_dtd_attribute_default default_mode;
144   char *default_value;
145 };
146
147 struct xml_dtd_eval {
148   struct xml_dtd_attr *attr;
149   char *val;
150 };
151
152 struct xml_dtd_enotn {
153   struct xml_dtd_attr *attr;
154   struct xml_dtd_notn *notn;
155 };
156
157 void xml_dtd_init(struct xml_context *ctx);
158 void xml_dtd_cleanup(struct xml_context *ctx);
159 void xml_dtd_finish(struct xml_context *ctx);
160
161 struct xml_dtd_attr *xml_dtd_find_attr(struct xml_context *ctx, struct xml_dtd_elem *elem, char *name);
162
163 #endif