blob: ef659079b5377ff6316e4666a6abea53d2945117 [file] [log] [blame]
Daniel Veillard39a1f9a1999-01-17 19:11:59 +00001/*
2 * valid.h : interface to the DTD handling and the validity checking
3 *
4 * See Copyright for the status of this software.
5 *
6 * Daniel.Veillard@w3.org
7 */
8
9
10#ifndef __XML_VALID_H__
11#define __XML_VALID_H__
Daniel Veillardc26087b1999-08-30 11:23:51 +000012
Daniel Veillard361d8452000-04-03 19:48:13 +000013#include <libxml/tree.h>
Daniel Veillard10cb9001999-11-12 17:02:31 +000014
Daniel Veillardc26087b1999-08-30 11:23:51 +000015#ifdef __cplusplus
16extern "C" {
17#endif
18
Daniel Veillardb05deb71999-08-10 19:04:08 +000019/**
20 * an xmlValidCtxt is used for error reporting when validating
21 */
22
23typedef void (*xmlValidityErrorFunc) (void *ctx, const char *msg, ...);
24typedef void (*xmlValidityWarningFunc) (void *ctx, const char *msg, ...);
25
Daniel Veillard71b656e2000-01-05 14:46:17 +000026typedef struct _xmlValidCtxt xmlValidCtxt;
27typedef xmlValidCtxt *xmlValidCtxtPtr;
28struct _xmlValidCtxt {
Daniel Veillardb05deb71999-08-10 19:04:08 +000029 void *userData; /* user specific data block */
30 xmlValidityErrorFunc error; /* the callback in case of errors */
31 xmlValidityWarningFunc warning; /* the callback in case of warning */
Daniel Veillardcf461992000-03-14 18:30:20 +000032
33 /* Node analysis stack used when validating within entities */
34 xmlNodePtr node; /* Current parsed Node */
35 int nodeNr; /* Depth of the parsing stack */
36 int nodeMax; /* Max depth of the parsing stack */
37 xmlNodePtr *nodeTab; /* array of nodes */
38
39 int finishDtd; /* finished validating the Dtd ? */
Daniel Veillard71b656e2000-01-05 14:46:17 +000040};
Daniel Veillardb05deb71999-08-10 19:04:08 +000041
Daniel Veillard3b9def11999-01-31 22:15:06 +000042/*
Daniel Veillard1e346af1999-02-22 10:33:01 +000043 * ALl notation declarations are stored in a table
44 * there is one table per DTD
45 */
46
47#define XML_MIN_NOTATION_TABLE 32
48
Daniel Veillard71b656e2000-01-05 14:46:17 +000049typedef struct _xmlNotationTable xmlNotationTable;
50typedef xmlNotationTable *xmlNotationTablePtr;
51struct _xmlNotationTable {
Daniel Veillard1e346af1999-02-22 10:33:01 +000052 int nb_notations; /* number of notations stored */
53 int max_notations; /* maximum number of notations */
Daniel Veillardb05deb71999-08-10 19:04:08 +000054 xmlNotationPtr *table; /* the table of attributes */
Daniel Veillard71b656e2000-01-05 14:46:17 +000055};
Daniel Veillard1e346af1999-02-22 10:33:01 +000056
57/*
Daniel Veillard3b9def11999-01-31 22:15:06 +000058 * ALl element declarations are stored in a table
59 * there is one table per DTD
60 */
61
62#define XML_MIN_ELEMENT_TABLE 32
63
Daniel Veillard71b656e2000-01-05 14:46:17 +000064typedef struct _xmlElementTable xmlElementTable;
65typedef xmlElementTable *xmlElementTablePtr;
66struct _xmlElementTable {
Daniel Veillard3b9def11999-01-31 22:15:06 +000067 int nb_elements; /* number of elements stored */
68 int max_elements; /* maximum number of elements */
Daniel Veillardb05deb71999-08-10 19:04:08 +000069 xmlElementPtr *table; /* the table of elements */
Daniel Veillard71b656e2000-01-05 14:46:17 +000070};
Daniel Veillard3b9def11999-01-31 22:15:06 +000071
Daniel Veillard1e346af1999-02-22 10:33:01 +000072/*
73 * ALl attribute declarations are stored in a table
74 * there is one table per DTD
75 */
76
77#define XML_MIN_ATTRIBUTE_TABLE 32
78
Daniel Veillard71b656e2000-01-05 14:46:17 +000079typedef struct _xmlAttributeTable xmlAttributeTable;
80typedef xmlAttributeTable *xmlAttributeTablePtr;
81struct _xmlAttributeTable {
Daniel Veillard1e346af1999-02-22 10:33:01 +000082 int nb_attributes; /* number of attributes stored */
83 int max_attributes; /* maximum number of attributes */
Daniel Veillardb05deb71999-08-10 19:04:08 +000084 xmlAttributePtr *table; /* the table of attributes */
Daniel Veillard71b656e2000-01-05 14:46:17 +000085};
Daniel Veillard1e346af1999-02-22 10:33:01 +000086
Daniel Veillard991e63d1999-08-15 23:32:28 +000087/*
88 * ALl IDs attributes are stored in a table
89 * there is one table per document
90 */
91
92#define XML_MIN_ID_TABLE 32
93
Daniel Veillard71b656e2000-01-05 14:46:17 +000094typedef struct _xmlIDTable xmlIDTable;
95typedef xmlIDTable *xmlIDTablePtr;
96struct _xmlIDTable {
Daniel Veillard991e63d1999-08-15 23:32:28 +000097 int nb_ids; /* number of ids stored */
98 int max_ids; /* maximum number of ids */
99 xmlIDPtr *table; /* the table of ids */
Daniel Veillard71b656e2000-01-05 14:46:17 +0000100};
Daniel Veillard991e63d1999-08-15 23:32:28 +0000101
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000102/*
103 * ALl Refs attributes are stored in a table
104 * there is one table per document
105 */
106
107#define XML_MIN_REF_TABLE 32
108
Daniel Veillard71b656e2000-01-05 14:46:17 +0000109typedef struct _xmlRefTable xmlRefTable;
110typedef xmlRefTable *xmlRefTablePtr;
111struct _xmlRefTable {
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000112 int nb_refs; /* number of refs stored */
113 int max_refs; /* maximum number of refs */
114 xmlRefPtr *table; /* the table of refs */
Daniel Veillard71b656e2000-01-05 14:46:17 +0000115};
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000116
Daniel Veillard1e346af1999-02-22 10:33:01 +0000117/* Notation */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000118xmlNotationPtr xmlAddNotationDecl (xmlValidCtxtPtr ctxt,
119 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000120 const xmlChar *name,
121 const xmlChar *PublicID,
122 const xmlChar *SystemID);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000123xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000124void xmlFreeNotationTable(xmlNotationTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000125void xmlDumpNotationDecl (xmlBufferPtr buf,
126 xmlNotationPtr nota);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000127void xmlDumpNotationTable(xmlBufferPtr buf,
128 xmlNotationTablePtr table);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000129
130/* Element Content */
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000131xmlElementContentPtr xmlNewElementContent (xmlChar *name,
Daniel Veillardc26087b1999-08-30 11:23:51 +0000132 xmlElementContentType type);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000133xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000134void xmlFreeElementContent(xmlElementContentPtr cur);
Daniel Veillardcf461992000-03-14 18:30:20 +0000135void xmlSprintfElementContent(char *buf,
136 xmlElementContentPtr content,
137 int glob);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000138
139/* Element */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000140xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt,
141 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000142 const xmlChar *name,
Daniel Veillard51e3b151999-11-12 17:02:31 +0000143 xmlElementTypeVal type,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000144 xmlElementContentPtr content);
145xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table);
146void xmlFreeElementTable (xmlElementTablePtr table);
147void xmlDumpElementTable (xmlBufferPtr buf,
148 xmlElementTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000149void xmlDumpElementDecl (xmlBufferPtr buf,
150 xmlElementPtr elem);
Daniel Veillard3b9def11999-01-31 22:15:06 +0000151
Daniel Veillard1e346af1999-02-22 10:33:01 +0000152/* Enumeration */
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000153xmlEnumerationPtr xmlCreateEnumeration (xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000154void xmlFreeEnumeration (xmlEnumerationPtr cur);
155xmlEnumerationPtr xmlCopyEnumeration (xmlEnumerationPtr cur);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000156
157/* Attribute */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000158xmlAttributePtr xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,
159 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000160 const xmlChar *elem,
161 const xmlChar *name,
Daniel Veillardcf461992000-03-14 18:30:20 +0000162 const xmlChar *prefix,
Daniel Veillardc26087b1999-08-30 11:23:51 +0000163 xmlAttributeType type,
164 xmlAttributeDefault def,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000165 const xmlChar *defaultValue,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000166 xmlEnumerationPtr tree);
167xmlAttributeTablePtr xmlCopyAttributeTable (xmlAttributeTablePtr table);
168void xmlFreeAttributeTable (xmlAttributeTablePtr table);
169void xmlDumpAttributeTable (xmlBufferPtr buf,
170 xmlAttributeTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000171void xmlDumpAttributeDecl (xmlBufferPtr buf,
172 xmlAttributePtr attr);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000173
Daniel Veillard991e63d1999-08-15 23:32:28 +0000174/* IDs */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000175xmlIDPtr xmlAddID (xmlValidCtxtPtr ctxt,
176 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000177 const xmlChar *value,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000178 xmlAttrPtr attr);
179xmlIDTablePtr xmlCopyIDTable (xmlIDTablePtr table);
180void xmlFreeIDTable (xmlIDTablePtr table);
181xmlAttrPtr xmlGetID (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000182 const xmlChar *ID);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000183int xmlIsID (xmlDocPtr doc,
184 xmlNodePtr elem,
185 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000186int xmlRemoveID (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillard991e63d1999-08-15 23:32:28 +0000187
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000188/* IDREFs */
189xmlRefPtr xmlAddRef (xmlValidCtxtPtr ctxt,
190 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000191 const xmlChar *value,
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000192 xmlAttrPtr attr);
193xmlRefTablePtr xmlCopyRefTable (xmlRefTablePtr table);
194void xmlFreeRefTable (xmlRefTablePtr table);
195int xmlIsRef (xmlDocPtr doc,
196 xmlNodePtr elem,
197 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000198int xmlRemoveRef (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000199
Daniel Veillardb05deb71999-08-10 19:04:08 +0000200/**
201 * The public function calls related to validity checking
202 */
203
Daniel Veillardb96e6431999-08-29 21:02:19 +0000204int xmlValidateRoot (xmlValidCtxtPtr ctxt,
205 xmlDocPtr doc);
206int xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
207 xmlDocPtr doc,
208 xmlElementPtr elem);
Daniel Veillardcf461992000-03-14 18:30:20 +0000209xmlChar * xmlValidNormalizeAttributeValue(xmlDocPtr doc,
210 xmlNodePtr elem,
211 const xmlChar *name,
212 const xmlChar *value);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000213int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
214 xmlDocPtr doc,
215 xmlAttributePtr attr);
216int xmlValidateAttributeValue(xmlAttributeType type,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000217 const xmlChar *value);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000218int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
219 xmlDocPtr doc,
220 xmlNotationPtr nota);
221int xmlValidateDtd (xmlValidCtxtPtr ctxt,
222 xmlDocPtr doc,
223 xmlDtdPtr dtd);
Daniel Veillardcf461992000-03-14 18:30:20 +0000224int xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
225 xmlDocPtr doc);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000226int xmlValidateDocument (xmlValidCtxtPtr ctxt,
227 xmlDocPtr doc);
228int xmlValidateElement (xmlValidCtxtPtr ctxt,
229 xmlDocPtr doc,
230 xmlNodePtr elem);
231int xmlValidateOneElement (xmlValidCtxtPtr ctxt,
232 xmlDocPtr doc,
233 xmlNodePtr elem);
234int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
235 xmlDocPtr doc,
236 xmlNodePtr elem,
237 xmlAttrPtr attr,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000238 const xmlChar *value);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000239int xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
240 xmlDocPtr doc);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000241int xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
242 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000243 const xmlChar *notationName);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000244int xmlIsMixedElement (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000245 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000246xmlAttributePtr xmlGetDtdAttrDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000247 const xmlChar *elem,
248 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000249xmlNotationPtr xmlGetDtdNotationDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000250 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000251xmlElementPtr xmlGetDtdElementDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000252 const xmlChar *name);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000253
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000254int xmlValidGetValidElements(xmlNode *prev,
255 xmlNode *next,
256 const xmlChar **list,
257 int max);
258int xmlValidGetPotentialChildren(xmlElementContent *ctree,
259 const xmlChar **list,
260 int *len,
261 int max);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000262#ifdef __cplusplus
263}
264#endif
Daniel Veillard39a1f9a1999-01-17 19:11:59 +0000265#endif /* __XML_VALID_H__ */