blob: ff7a9af1edd8595e8610ab4a43d09ef1580e46b9 [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 Veillardf0cc7cc2000-08-26 21:40:43 +000070 int last; /* last element accessed */
Daniel Veillard71b656e2000-01-05 14:46:17 +000071};
Daniel Veillard3b9def11999-01-31 22:15:06 +000072
Daniel Veillard1e346af1999-02-22 10:33:01 +000073/*
74 * ALl attribute declarations are stored in a table
75 * there is one table per DTD
76 */
77
78#define XML_MIN_ATTRIBUTE_TABLE 32
79
Daniel Veillard71b656e2000-01-05 14:46:17 +000080typedef struct _xmlAttributeTable xmlAttributeTable;
81typedef xmlAttributeTable *xmlAttributeTablePtr;
82struct _xmlAttributeTable {
Daniel Veillard1e346af1999-02-22 10:33:01 +000083 int nb_attributes; /* number of attributes stored */
84 int max_attributes; /* maximum number of attributes */
Daniel Veillardb05deb71999-08-10 19:04:08 +000085 xmlAttributePtr *table; /* the table of attributes */
Daniel Veillard71b656e2000-01-05 14:46:17 +000086};
Daniel Veillard1e346af1999-02-22 10:33:01 +000087
Daniel Veillard991e63d1999-08-15 23:32:28 +000088/*
89 * ALl IDs attributes are stored in a table
90 * there is one table per document
91 */
92
93#define XML_MIN_ID_TABLE 32
94
Daniel Veillard71b656e2000-01-05 14:46:17 +000095typedef struct _xmlIDTable xmlIDTable;
96typedef xmlIDTable *xmlIDTablePtr;
97struct _xmlIDTable {
Daniel Veillard991e63d1999-08-15 23:32:28 +000098 int nb_ids; /* number of ids stored */
99 int max_ids; /* maximum number of ids */
100 xmlIDPtr *table; /* the table of ids */
Daniel Veillard71b656e2000-01-05 14:46:17 +0000101};
Daniel Veillard991e63d1999-08-15 23:32:28 +0000102
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000103/*
104 * ALl Refs attributes are stored in a table
105 * there is one table per document
106 */
107
108#define XML_MIN_REF_TABLE 32
109
Daniel Veillard71b656e2000-01-05 14:46:17 +0000110typedef struct _xmlRefTable xmlRefTable;
111typedef xmlRefTable *xmlRefTablePtr;
112struct _xmlRefTable {
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000113 int nb_refs; /* number of refs stored */
114 int max_refs; /* maximum number of refs */
115 xmlRefPtr *table; /* the table of refs */
Daniel Veillard71b656e2000-01-05 14:46:17 +0000116};
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000117
Daniel Veillard1e346af1999-02-22 10:33:01 +0000118/* Notation */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000119xmlNotationPtr xmlAddNotationDecl (xmlValidCtxtPtr ctxt,
120 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000121 const xmlChar *name,
122 const xmlChar *PublicID,
123 const xmlChar *SystemID);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000124xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000125void xmlFreeNotationTable(xmlNotationTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000126void xmlDumpNotationDecl (xmlBufferPtr buf,
127 xmlNotationPtr nota);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000128void xmlDumpNotationTable(xmlBufferPtr buf,
129 xmlNotationTablePtr table);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000130
131/* Element Content */
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000132xmlElementContentPtr xmlNewElementContent (xmlChar *name,
Daniel Veillardc26087b1999-08-30 11:23:51 +0000133 xmlElementContentType type);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000134xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000135void xmlFreeElementContent(xmlElementContentPtr cur);
Daniel Veillardcf461992000-03-14 18:30:20 +0000136void xmlSprintfElementContent(char *buf,
137 xmlElementContentPtr content,
138 int glob);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000139
140/* Element */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000141xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt,
142 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000143 const xmlChar *name,
Daniel Veillard51e3b151999-11-12 17:02:31 +0000144 xmlElementTypeVal type,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000145 xmlElementContentPtr content);
146xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table);
147void xmlFreeElementTable (xmlElementTablePtr table);
148void xmlDumpElementTable (xmlBufferPtr buf,
149 xmlElementTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000150void xmlDumpElementDecl (xmlBufferPtr buf,
151 xmlElementPtr elem);
Daniel Veillard3b9def11999-01-31 22:15:06 +0000152
Daniel Veillard1e346af1999-02-22 10:33:01 +0000153/* Enumeration */
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000154xmlEnumerationPtr xmlCreateEnumeration (xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000155void xmlFreeEnumeration (xmlEnumerationPtr cur);
156xmlEnumerationPtr xmlCopyEnumeration (xmlEnumerationPtr cur);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000157
158/* Attribute */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000159xmlAttributePtr xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,
160 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000161 const xmlChar *elem,
162 const xmlChar *name,
Daniel Veillard06047432000-04-24 11:33:38 +0000163 const xmlChar *ns,
Daniel Veillardc26087b1999-08-30 11:23:51 +0000164 xmlAttributeType type,
165 xmlAttributeDefault def,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000166 const xmlChar *defaultValue,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000167 xmlEnumerationPtr tree);
168xmlAttributeTablePtr xmlCopyAttributeTable (xmlAttributeTablePtr table);
169void xmlFreeAttributeTable (xmlAttributeTablePtr table);
170void xmlDumpAttributeTable (xmlBufferPtr buf,
171 xmlAttributeTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000172void xmlDumpAttributeDecl (xmlBufferPtr buf,
173 xmlAttributePtr attr);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000174
Daniel Veillard991e63d1999-08-15 23:32:28 +0000175/* IDs */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000176xmlIDPtr xmlAddID (xmlValidCtxtPtr ctxt,
177 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000178 const xmlChar *value,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000179 xmlAttrPtr attr);
180xmlIDTablePtr xmlCopyIDTable (xmlIDTablePtr table);
181void xmlFreeIDTable (xmlIDTablePtr table);
182xmlAttrPtr xmlGetID (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000183 const xmlChar *ID);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000184int xmlIsID (xmlDocPtr doc,
185 xmlNodePtr elem,
186 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000187int xmlRemoveID (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillard991e63d1999-08-15 23:32:28 +0000188
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000189/* IDREFs */
190xmlRefPtr xmlAddRef (xmlValidCtxtPtr ctxt,
191 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000192 const xmlChar *value,
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000193 xmlAttrPtr attr);
194xmlRefTablePtr xmlCopyRefTable (xmlRefTablePtr table);
195void xmlFreeRefTable (xmlRefTablePtr table);
196int xmlIsRef (xmlDocPtr doc,
197 xmlNodePtr elem,
198 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000199int xmlRemoveRef (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000200
Daniel Veillardb05deb71999-08-10 19:04:08 +0000201/**
202 * The public function calls related to validity checking
203 */
204
Daniel Veillardb96e6431999-08-29 21:02:19 +0000205int xmlValidateRoot (xmlValidCtxtPtr ctxt,
206 xmlDocPtr doc);
207int xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
208 xmlDocPtr doc,
209 xmlElementPtr elem);
Daniel Veillardcf461992000-03-14 18:30:20 +0000210xmlChar * xmlValidNormalizeAttributeValue(xmlDocPtr doc,
211 xmlNodePtr elem,
212 const xmlChar *name,
213 const xmlChar *value);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000214int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
215 xmlDocPtr doc,
216 xmlAttributePtr attr);
217int xmlValidateAttributeValue(xmlAttributeType type,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000218 const xmlChar *value);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000219int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
220 xmlDocPtr doc,
221 xmlNotationPtr nota);
222int xmlValidateDtd (xmlValidCtxtPtr ctxt,
223 xmlDocPtr doc,
224 xmlDtdPtr dtd);
Daniel Veillardcf461992000-03-14 18:30:20 +0000225int xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
226 xmlDocPtr doc);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000227int xmlValidateDocument (xmlValidCtxtPtr ctxt,
228 xmlDocPtr doc);
229int xmlValidateElement (xmlValidCtxtPtr ctxt,
230 xmlDocPtr doc,
231 xmlNodePtr elem);
232int xmlValidateOneElement (xmlValidCtxtPtr ctxt,
233 xmlDocPtr doc,
234 xmlNodePtr elem);
235int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
236 xmlDocPtr doc,
237 xmlNodePtr elem,
238 xmlAttrPtr attr,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000239 const xmlChar *value);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000240int xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
241 xmlDocPtr doc);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000242int xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
243 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000244 const xmlChar *notationName);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000245int xmlIsMixedElement (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000246 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000247xmlAttributePtr xmlGetDtdAttrDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000248 const xmlChar *elem,
249 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000250xmlNotationPtr xmlGetDtdNotationDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000251 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000252xmlElementPtr xmlGetDtdElementDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000253 const xmlChar *name);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000254
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000255int xmlValidGetValidElements(xmlNode *prev,
256 xmlNode *next,
257 const xmlChar **list,
258 int max);
259int xmlValidGetPotentialChildren(xmlElementContent *ctree,
260 const xmlChar **list,
261 int *len,
262 int max);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000263#ifdef __cplusplus
264}
265#endif
Daniel Veillard39a1f9a1999-01-17 19:11:59 +0000266#endif /* __XML_VALID_H__ */