blob: 8c86b17b3b35c4481e7054d9faba9a4e985364df [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 Veillard10cb9001999-11-12 17:02:31 +000013#include "tree.h"
14
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 Veillard71b656e2000-01-05 14:46:17 +000032};
Daniel Veillardb05deb71999-08-10 19:04:08 +000033
Daniel Veillard3b9def11999-01-31 22:15:06 +000034/*
Daniel Veillard1e346af1999-02-22 10:33:01 +000035 * ALl notation declarations are stored in a table
36 * there is one table per DTD
37 */
38
39#define XML_MIN_NOTATION_TABLE 32
40
Daniel Veillard71b656e2000-01-05 14:46:17 +000041typedef struct _xmlNotationTable xmlNotationTable;
42typedef xmlNotationTable *xmlNotationTablePtr;
43struct _xmlNotationTable {
Daniel Veillard1e346af1999-02-22 10:33:01 +000044 int nb_notations; /* number of notations stored */
45 int max_notations; /* maximum number of notations */
Daniel Veillardb05deb71999-08-10 19:04:08 +000046 xmlNotationPtr *table; /* the table of attributes */
Daniel Veillard71b656e2000-01-05 14:46:17 +000047};
Daniel Veillard1e346af1999-02-22 10:33:01 +000048
49/*
Daniel Veillard3b9def11999-01-31 22:15:06 +000050 * ALl element declarations are stored in a table
51 * there is one table per DTD
52 */
53
54#define XML_MIN_ELEMENT_TABLE 32
55
Daniel Veillard71b656e2000-01-05 14:46:17 +000056typedef struct _xmlElementTable xmlElementTable;
57typedef xmlElementTable *xmlElementTablePtr;
58struct _xmlElementTable {
Daniel Veillard3b9def11999-01-31 22:15:06 +000059 int nb_elements; /* number of elements stored */
60 int max_elements; /* maximum number of elements */
Daniel Veillardb05deb71999-08-10 19:04:08 +000061 xmlElementPtr *table; /* the table of elements */
Daniel Veillard71b656e2000-01-05 14:46:17 +000062};
Daniel Veillard3b9def11999-01-31 22:15:06 +000063
Daniel Veillard1e346af1999-02-22 10:33:01 +000064/*
65 * ALl attribute declarations are stored in a table
66 * there is one table per DTD
67 */
68
69#define XML_MIN_ATTRIBUTE_TABLE 32
70
Daniel Veillard71b656e2000-01-05 14:46:17 +000071typedef struct _xmlAttributeTable xmlAttributeTable;
72typedef xmlAttributeTable *xmlAttributeTablePtr;
73struct _xmlAttributeTable {
Daniel Veillard1e346af1999-02-22 10:33:01 +000074 int nb_attributes; /* number of attributes stored */
75 int max_attributes; /* maximum number of attributes */
Daniel Veillardb05deb71999-08-10 19:04:08 +000076 xmlAttributePtr *table; /* the table of attributes */
Daniel Veillard71b656e2000-01-05 14:46:17 +000077};
Daniel Veillard1e346af1999-02-22 10:33:01 +000078
Daniel Veillard991e63d1999-08-15 23:32:28 +000079/*
80 * ALl IDs attributes are stored in a table
81 * there is one table per document
82 */
83
84#define XML_MIN_ID_TABLE 32
85
Daniel Veillard71b656e2000-01-05 14:46:17 +000086typedef struct _xmlIDTable xmlIDTable;
87typedef xmlIDTable *xmlIDTablePtr;
88struct _xmlIDTable {
Daniel Veillard991e63d1999-08-15 23:32:28 +000089 int nb_ids; /* number of ids stored */
90 int max_ids; /* maximum number of ids */
91 xmlIDPtr *table; /* the table of ids */
Daniel Veillard71b656e2000-01-05 14:46:17 +000092};
Daniel Veillard991e63d1999-08-15 23:32:28 +000093
Daniel Veillardc08a2c61999-09-08 21:35:25 +000094/*
95 * ALl Refs attributes are stored in a table
96 * there is one table per document
97 */
98
99#define XML_MIN_REF_TABLE 32
100
Daniel Veillard71b656e2000-01-05 14:46:17 +0000101typedef struct _xmlRefTable xmlRefTable;
102typedef xmlRefTable *xmlRefTablePtr;
103struct _xmlRefTable {
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000104 int nb_refs; /* number of refs stored */
105 int max_refs; /* maximum number of refs */
106 xmlRefPtr *table; /* the table of refs */
Daniel Veillard71b656e2000-01-05 14:46:17 +0000107};
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000108
Daniel Veillard1e346af1999-02-22 10:33:01 +0000109/* Notation */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000110xmlNotationPtr xmlAddNotationDecl (xmlValidCtxtPtr ctxt,
111 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000112 const xmlChar *name,
113 const xmlChar *PublicID,
114 const xmlChar *SystemID);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000115xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000116void xmlFreeNotationTable(xmlNotationTablePtr table);
117void xmlDumpNotationTable(xmlBufferPtr buf,
118 xmlNotationTablePtr table);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000119
120/* Element Content */
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000121xmlElementContentPtr xmlNewElementContent (xmlChar *name,
Daniel Veillardc26087b1999-08-30 11:23:51 +0000122 xmlElementContentType type);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000123xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000124void xmlFreeElementContent(xmlElementContentPtr cur);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000125
126/* Element */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000127xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt,
128 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000129 const xmlChar *name,
Daniel Veillard51e3b151999-11-12 17:02:31 +0000130 xmlElementTypeVal type,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000131 xmlElementContentPtr content);
132xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table);
133void xmlFreeElementTable (xmlElementTablePtr table);
134void xmlDumpElementTable (xmlBufferPtr buf,
135 xmlElementTablePtr table);
Daniel Veillard3b9def11999-01-31 22:15:06 +0000136
Daniel Veillard1e346af1999-02-22 10:33:01 +0000137/* Enumeration */
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000138xmlEnumerationPtr xmlCreateEnumeration (xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000139void xmlFreeEnumeration (xmlEnumerationPtr cur);
140xmlEnumerationPtr xmlCopyEnumeration (xmlEnumerationPtr cur);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000141
142/* Attribute */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000143xmlAttributePtr xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,
144 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000145 const xmlChar *elem,
146 const xmlChar *name,
Daniel Veillardc26087b1999-08-30 11:23:51 +0000147 xmlAttributeType type,
148 xmlAttributeDefault def,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000149 const xmlChar *defaultValue,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000150 xmlEnumerationPtr tree);
151xmlAttributeTablePtr xmlCopyAttributeTable (xmlAttributeTablePtr table);
152void xmlFreeAttributeTable (xmlAttributeTablePtr table);
153void xmlDumpAttributeTable (xmlBufferPtr buf,
154 xmlAttributeTablePtr table);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000155
Daniel Veillard991e63d1999-08-15 23:32:28 +0000156/* IDs */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000157xmlIDPtr xmlAddID (xmlValidCtxtPtr ctxt,
158 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000159 const xmlChar *value,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000160 xmlAttrPtr attr);
161xmlIDTablePtr xmlCopyIDTable (xmlIDTablePtr table);
162void xmlFreeIDTable (xmlIDTablePtr table);
163xmlAttrPtr xmlGetID (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000164 const xmlChar *ID);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000165int xmlIsID (xmlDocPtr doc,
166 xmlNodePtr elem,
167 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000168int xmlRemoveID (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillard991e63d1999-08-15 23:32:28 +0000169
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000170/* IDREFs */
171xmlRefPtr xmlAddRef (xmlValidCtxtPtr ctxt,
172 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000173 const xmlChar *value,
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000174 xmlAttrPtr attr);
175xmlRefTablePtr xmlCopyRefTable (xmlRefTablePtr table);
176void xmlFreeRefTable (xmlRefTablePtr table);
177int xmlIsRef (xmlDocPtr doc,
178 xmlNodePtr elem,
179 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000180int xmlRemoveRef (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000181
Daniel Veillardb05deb71999-08-10 19:04:08 +0000182/**
183 * The public function calls related to validity checking
184 */
185
Daniel Veillardb96e6431999-08-29 21:02:19 +0000186int xmlValidateRoot (xmlValidCtxtPtr ctxt,
187 xmlDocPtr doc);
188int xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
189 xmlDocPtr doc,
190 xmlElementPtr elem);
191int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
192 xmlDocPtr doc,
193 xmlAttributePtr attr);
194int xmlValidateAttributeValue(xmlAttributeType type,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000195 const xmlChar *value);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000196int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
197 xmlDocPtr doc,
198 xmlNotationPtr nota);
199int xmlValidateDtd (xmlValidCtxtPtr ctxt,
200 xmlDocPtr doc,
201 xmlDtdPtr dtd);
202int xmlValidateDocument (xmlValidCtxtPtr ctxt,
203 xmlDocPtr doc);
204int xmlValidateElement (xmlValidCtxtPtr ctxt,
205 xmlDocPtr doc,
206 xmlNodePtr elem);
207int xmlValidateOneElement (xmlValidCtxtPtr ctxt,
208 xmlDocPtr doc,
209 xmlNodePtr elem);
210int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
211 xmlDocPtr doc,
212 xmlNodePtr elem,
213 xmlAttrPtr attr,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000214 const xmlChar *value);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000215int xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
216 xmlDocPtr doc);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000217int xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
218 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000219 const xmlChar *notationName);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000220int xmlIsMixedElement (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000221 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000222xmlAttributePtr xmlGetDtdAttrDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000223 const xmlChar *elem,
224 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000225xmlNotationPtr xmlGetDtdNotationDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000226 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000227xmlElementPtr xmlGetDtdElementDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000228 const xmlChar *name);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000229
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000230int xmlValidGetValidElements(xmlNode *prev,
231 xmlNode *next,
232 const xmlChar **list,
233 int max);
234int xmlValidGetPotentialChildren(xmlElementContent *ctree,
235 const xmlChar **list,
236 int *len,
237 int max);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000238#ifdef __cplusplus
239}
240#endif
Daniel Veillard39a1f9a1999-01-17 19:11:59 +0000241#endif /* __XML_VALID_H__ */