]> mj.ucw.cz Git - libucw.git/blob - sherlock/xml/dtd.h
bf95b872e70d68e6c44d8198ab9fd8303566a1ed
[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 gents;                          /* 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_gents;                      /* 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 (interbal 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   struct xml_ext_id eid;                /* External id */
42 };
43
44 /* Entities */
45
46 enum xml_dtd_ent_flags {
47   XML_DTD_ENT_DECLARED = 0x1,           /* The entity has been declared (internal usage) */
48   XML_DTD_ENT_VISITED = 0x2,            /* Cycle detection (internal usage) */
49   XML_DTD_ENT_PARAMETER = 0x4,          /* Parameter entity, general otherwise */
50   XML_DTD_ENT_EXTERNAL = 0x8,           /* External entity, internal otherwise */
51   XML_DTD_ENT_UNPARSED = 0x10,          /* Unparsed entity, parsed otherwise */
52   XML_DTD_ENT_TRIVIAL = 0x20,           /* Replacement text is a sequence of characters and character references */
53 };
54
55 struct xml_dtd_ent {
56   snode n;                              /* Node in xml_dtd.[gp]ents */
57   uns flags;                            /* XML_DTD_ENT_x */
58   char *name;                           /* Entity name */
59   char *text;                           /* Replacement text / expanded replacement text (XML_DTD_ENT_TRIVIAL) */
60   uns len;                              /* Text length */
61   struct xml_ext_id eid;                /* External ID */
62   struct xml_dtd_notn *notn;            /* Notation (XML_DTD_ENT_UNPARSED only) */
63 };
64
65 /* Elements */
66
67 enum xml_dtd_elem_flags {
68   XML_DTD_ELEM_DECLARED = 0x1,          /* The element has been declared (internal usage) */
69 };
70
71 enum xml_dtd_elem_type {
72   XML_DTD_ELEM_EMPTY,
73   XML_DTD_ELEM_ANY,
74   XML_DTD_ELEM_MIXED,
75   XML_DTD_ELEM_CHILDREN,
76 };
77
78 struct xml_dtd_elem {
79   snode n;
80   uns flags;
81   uns type;
82   char *name;
83   struct xml_dtd_elem_node *node;
84 };
85
86 struct xml_dtd_elem_node {
87   snode n;
88   struct xml_dtd_elem_node *parent;
89   struct xml_dtd_elem *elem;
90   slist sons;
91   uns type;
92   uns occur;
93 };
94
95 enum xml_dtd_elem_node_type {
96   XML_DTD_ELEM_PCDATA,
97   XML_DTD_ELEM_SEQ,
98   XML_DTD_ELEM_OR,
99 };
100
101 enum xml_dtd_elem_node_occur {
102   XML_DTD_ELEM_OCCUR_ONCE,
103   XML_DTD_ELEM_OCCUR_OPT,
104   XML_DTD_ELEM_OCCUR_MULT,
105   XML_DTD_ELEM_OCCUR_PLUS,
106 };
107
108 /* Attributes */
109
110 enum xml_dtd_attribute_default {
111   XML_ATTR_NONE,
112   XML_ATTR_REQUIRED,
113   XML_ATTR_IMPLIED,
114   XML_ATTR_FIXED,
115 };
116
117 enum xml_dtd_attribute_type {
118   XML_ATTR_CDATA,
119   XML_ATTR_ID,
120   XML_ATTR_IDREF,
121   XML_ATTR_IDREFS,
122   XML_ATTR_ENTITY,
123   XML_ATTR_ENTITIES,
124   XML_ATTR_NMTOKEN,
125   XML_ATTR_NMTOKENS,
126   XML_ATTR_ENUM,
127   XML_ATTR_NOTATION,
128 };
129
130 struct xml_dtd_attr {
131   char *name;
132   struct xml_dtd_elem *elem;
133   enum xml_dtd_attribute_type type;
134   enum xml_dtd_attribute_default default_mode;
135   char *default_value;
136 };
137
138 struct xml_dtd_eval {
139   struct xml_dtd_attr *attr;
140   char *val;
141 };
142
143 struct xml_dtd_enotn {
144   struct xml_dtd_attr *attr;
145   struct xml_dtd_notn *notn;
146 };
147
148 #endif