blob: 4cc5f9788d5cf6163d6db1515fa8824d964c9680 [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
2 * valid.h : interface to the DTD handling and the validity checking
3 *
4 * See Copyright for the status of this software.
5 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * daniel@veillard.com
Owen Taylor3473f882001-02-23 17:55:21 +00007 */
8
9
10#ifndef __XML_VALID_H__
11#define __XML_VALID_H__
12
13#include <libxml/tree.h>
Daniel Veillard56a4cb82001-03-24 17:00:36 +000014#include <libxml/list.h>
Daniel Veillardaeb258a2002-09-13 14:48:12 +000015#include <libxml/xmlautomata.h>
16#include <libxml/xmlregexp.h>
Owen Taylor3473f882001-02-23 17:55:21 +000017
18#ifdef __cplusplus
19extern "C" {
20#endif
21
Daniel Veillarddab4cb32001-04-20 13:03:48 +000022/*
Daniel Veillard61f26172002-03-12 18:46:39 +000023 * Validation state added for non-determinist content model.
Daniel Veillarddab4cb32001-04-20 13:03:48 +000024 */
25typedef struct _xmlValidState xmlValidState;
26typedef xmlValidState *xmlValidStatePtr;
27
Owen Taylor3473f882001-02-23 17:55:21 +000028/**
Daniel Veillard9d06d302002-01-22 18:15:52 +000029 * xmlValidityErrorFunc:
30 * @ctx: an xmlValidCtxtPtr validity error context
31 * @msg: the string to format *printf like vararg
32 * @...: remaining arguments to the format
33 *
Daniel Veillard61f26172002-03-12 18:46:39 +000034 * Callback called when a validity error is found. This is a message
Daniel Veillard9d06d302002-01-22 18:15:52 +000035 * oriented function similar to an *printf function.
36 */
37typedef void (*xmlValidityErrorFunc) (void *ctx,
38 const char *msg,
39 ...);
40
41/**
42 * xmlValidityWarningFunc:
43 * @ctx: an xmlValidCtxtPtr validity error context
44 * @msg: the string to format *printf like vararg
45 * @...: remaining arguments to the format
46 *
Daniel Veillard61f26172002-03-12 18:46:39 +000047 * Callback called when a validity warning is found. This is a message
Daniel Veillard9d06d302002-01-22 18:15:52 +000048 * oriented function similar to an *printf function.
49 */
50typedef void (*xmlValidityWarningFunc) (void *ctx,
51 const char *msg,
52 ...);
53
54/**
55 * xmlValidCtxt:
Daniel Veillard61f26172002-03-12 18:46:39 +000056 * An xmlValidCtxt is used for error reporting when validating.
Owen Taylor3473f882001-02-23 17:55:21 +000057 */
Owen Taylor3473f882001-02-23 17:55:21 +000058typedef struct _xmlValidCtxt xmlValidCtxt;
59typedef xmlValidCtxt *xmlValidCtxtPtr;
60struct _xmlValidCtxt {
61 void *userData; /* user specific data block */
62 xmlValidityErrorFunc error; /* the callback in case of errors */
63 xmlValidityWarningFunc warning; /* the callback in case of warning */
64
65 /* Node analysis stack used when validating within entities */
66 xmlNodePtr node; /* Current parsed Node */
67 int nodeNr; /* Depth of the parsing stack */
68 int nodeMax; /* Max depth of the parsing stack */
69 xmlNodePtr *nodeTab; /* array of nodes */
70
71 int finishDtd; /* finished validating the Dtd ? */
72 xmlDocPtr doc; /* the document */
73 int valid; /* temporary validity check result */
Daniel Veillarddab4cb32001-04-20 13:03:48 +000074
75 /* state state used for non-determinist content validation */
76 xmlValidState *vstate; /* current state */
77 int vstateNr; /* Depth of the validation stack */
78 int vstateMax; /* Max depth of the validation stack */
79 xmlValidState *vstateTab; /* array of validation states */
Daniel Veillardaeb258a2002-09-13 14:48:12 +000080
81#ifdef LIBXML_REGEXP_ENABLED
82 xmlAutomataPtr am; /* the automata */
83 xmlAutomataStatePtr state; /* used to build the automata */
84#else
85 void *am;
86 void *state;
87#endif
Owen Taylor3473f882001-02-23 17:55:21 +000088};
89
90/*
Daniel Veillard61f26172002-03-12 18:46:39 +000091 * ALL notation declarations are stored in a table.
92 * There is one table per DTD.
Owen Taylor3473f882001-02-23 17:55:21 +000093 */
94
95typedef struct _xmlHashTable xmlNotationTable;
96typedef xmlNotationTable *xmlNotationTablePtr;
97
98/*
Daniel Veillard61f26172002-03-12 18:46:39 +000099 * ALL element declarations are stored in a table.
100 * There is one table per DTD.
Owen Taylor3473f882001-02-23 17:55:21 +0000101 */
102
103typedef struct _xmlHashTable xmlElementTable;
104typedef xmlElementTable *xmlElementTablePtr;
105
106/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000107 * ALL attribute declarations are stored in a table.
108 * There is one table per DTD.
Owen Taylor3473f882001-02-23 17:55:21 +0000109 */
110
111typedef struct _xmlHashTable xmlAttributeTable;
112typedef xmlAttributeTable *xmlAttributeTablePtr;
113
114/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000115 * ALL IDs attributes are stored in a table.
116 * There is one table per document.
Owen Taylor3473f882001-02-23 17:55:21 +0000117 */
118
119typedef struct _xmlHashTable xmlIDTable;
120typedef xmlIDTable *xmlIDTablePtr;
121
122/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000123 * ALL Refs attributes are stored in a table.
124 * There is one table per document.
Owen Taylor3473f882001-02-23 17:55:21 +0000125 */
126
127typedef struct _xmlHashTable xmlRefTable;
128typedef xmlRefTable *xmlRefTablePtr;
129
130/* helper */
131xmlChar * xmlSplitQName2 (const xmlChar *name,
132 xmlChar **prefix);
133
134/* Notation */
135xmlNotationPtr xmlAddNotationDecl (xmlValidCtxtPtr ctxt,
136 xmlDtdPtr dtd,
137 const xmlChar *name,
138 const xmlChar *PublicID,
139 const xmlChar *SystemID);
140xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table);
141void xmlFreeNotationTable(xmlNotationTablePtr table);
142void xmlDumpNotationDecl (xmlBufferPtr buf,
143 xmlNotationPtr nota);
144void xmlDumpNotationTable(xmlBufferPtr buf,
145 xmlNotationTablePtr table);
146
147/* Element Content */
148xmlElementContentPtr xmlNewElementContent (xmlChar *name,
149 xmlElementContentType type);
150xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
151void xmlFreeElementContent(xmlElementContentPtr cur);
Daniel Veillardd3d06722001-08-15 12:06:36 +0000152void xmlSnprintfElementContent(char *buf,
153 int size,
154 xmlElementContentPtr content,
155 int glob);
156/* DEPRECATED */
Owen Taylor3473f882001-02-23 17:55:21 +0000157void xmlSprintfElementContent(char *buf,
158 xmlElementContentPtr content,
159 int glob);
Daniel Veillardd3d06722001-08-15 12:06:36 +0000160/* DEPRECATED */
Owen Taylor3473f882001-02-23 17:55:21 +0000161
162/* Element */
163xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt,
164 xmlDtdPtr dtd,
165 const xmlChar *name,
166 xmlElementTypeVal type,
167 xmlElementContentPtr content);
168xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table);
169void xmlFreeElementTable (xmlElementTablePtr table);
170void xmlDumpElementTable (xmlBufferPtr buf,
171 xmlElementTablePtr table);
172void xmlDumpElementDecl (xmlBufferPtr buf,
173 xmlElementPtr elem);
174
175/* Enumeration */
176xmlEnumerationPtr xmlCreateEnumeration (xmlChar *name);
177void xmlFreeEnumeration (xmlEnumerationPtr cur);
178xmlEnumerationPtr xmlCopyEnumeration (xmlEnumerationPtr cur);
179
180/* Attribute */
181xmlAttributePtr xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,
182 xmlDtdPtr dtd,
183 const xmlChar *elem,
184 const xmlChar *name,
185 const xmlChar *ns,
186 xmlAttributeType type,
187 xmlAttributeDefault def,
188 const xmlChar *defaultValue,
189 xmlEnumerationPtr tree);
190xmlAttributeTablePtr xmlCopyAttributeTable (xmlAttributeTablePtr table);
191void xmlFreeAttributeTable (xmlAttributeTablePtr table);
192void xmlDumpAttributeTable (xmlBufferPtr buf,
193 xmlAttributeTablePtr table);
194void xmlDumpAttributeDecl (xmlBufferPtr buf,
195 xmlAttributePtr attr);
196
197/* IDs */
198xmlIDPtr xmlAddID (xmlValidCtxtPtr ctxt,
199 xmlDocPtr doc,
200 const xmlChar *value,
201 xmlAttrPtr attr);
Owen Taylor3473f882001-02-23 17:55:21 +0000202void xmlFreeIDTable (xmlIDTablePtr table);
203xmlAttrPtr xmlGetID (xmlDocPtr doc,
204 const xmlChar *ID);
205int xmlIsID (xmlDocPtr doc,
206 xmlNodePtr elem,
207 xmlAttrPtr attr);
208int xmlRemoveID (xmlDocPtr doc, xmlAttrPtr attr);
209
210/* IDREFs */
211xmlRefPtr xmlAddRef (xmlValidCtxtPtr ctxt,
212 xmlDocPtr doc,
213 const xmlChar *value,
214 xmlAttrPtr attr);
Owen Taylor3473f882001-02-23 17:55:21 +0000215void xmlFreeRefTable (xmlRefTablePtr table);
216int xmlIsRef (xmlDocPtr doc,
217 xmlNodePtr elem,
218 xmlAttrPtr attr);
219int xmlRemoveRef (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000220xmlListPtr xmlGetRefs (xmlDocPtr doc,
221 const xmlChar *ID);
Owen Taylor3473f882001-02-23 17:55:21 +0000222
223/**
Daniel Veillard61f26172002-03-12 18:46:39 +0000224 * The public function calls related to validity checking.
Owen Taylor3473f882001-02-23 17:55:21 +0000225 */
226
227int xmlValidateRoot (xmlValidCtxtPtr ctxt,
228 xmlDocPtr doc);
229int xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
230 xmlDocPtr doc,
231 xmlElementPtr elem);
232xmlChar * xmlValidNormalizeAttributeValue(xmlDocPtr doc,
233 xmlNodePtr elem,
234 const xmlChar *name,
235 const xmlChar *value);
Daniel Veillard8dc16a62002-02-19 21:08:48 +0000236xmlChar * xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt,
237 xmlDocPtr doc,
238 xmlNodePtr elem,
239 const xmlChar *name,
240 const xmlChar *value);
Owen Taylor3473f882001-02-23 17:55:21 +0000241int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
242 xmlDocPtr doc,
243 xmlAttributePtr attr);
244int xmlValidateAttributeValue(xmlAttributeType type,
245 const xmlChar *value);
246int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
247 xmlDocPtr doc,
248 xmlNotationPtr nota);
249int xmlValidateDtd (xmlValidCtxtPtr ctxt,
250 xmlDocPtr doc,
251 xmlDtdPtr dtd);
252int xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
253 xmlDocPtr doc);
254int xmlValidateDocument (xmlValidCtxtPtr ctxt,
255 xmlDocPtr doc);
256int xmlValidateElement (xmlValidCtxtPtr ctxt,
257 xmlDocPtr doc,
258 xmlNodePtr elem);
259int xmlValidateOneElement (xmlValidCtxtPtr ctxt,
260 xmlDocPtr doc,
261 xmlNodePtr elem);
262int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
263 xmlDocPtr doc,
264 xmlNodePtr elem,
265 xmlAttrPtr attr,
266 const xmlChar *value);
Daniel Veillard90d68fb2002-09-26 16:10:21 +0000267int xmlValidateOneNamespace (xmlValidCtxtPtr ctxt,
268 xmlDocPtr doc,
269 xmlNodePtr elem,
270 const xmlChar *prefix,
271 xmlNsPtr ns,
272 const xmlChar *value);
Owen Taylor3473f882001-02-23 17:55:21 +0000273int xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
274 xmlDocPtr doc);
275int xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
276 xmlDocPtr doc,
277 const xmlChar *notationName);
278int xmlIsMixedElement (xmlDocPtr doc,
279 const xmlChar *name);
280xmlAttributePtr xmlGetDtdAttrDesc (xmlDtdPtr dtd,
281 const xmlChar *elem,
282 const xmlChar *name);
Daniel Veillard48da9102001-08-07 01:10:10 +0000283xmlAttributePtr xmlGetDtdQAttrDesc (xmlDtdPtr dtd,
284 const xmlChar *elem,
285 const xmlChar *name,
286 const xmlChar *prefix);
Owen Taylor3473f882001-02-23 17:55:21 +0000287xmlNotationPtr xmlGetDtdNotationDesc (xmlDtdPtr dtd,
288 const xmlChar *name);
Daniel Veillard48da9102001-08-07 01:10:10 +0000289xmlElementPtr xmlGetDtdQElementDesc (xmlDtdPtr dtd,
290 const xmlChar *name,
291 const xmlChar *prefix);
Owen Taylor3473f882001-02-23 17:55:21 +0000292xmlElementPtr xmlGetDtdElementDesc (xmlDtdPtr dtd,
293 const xmlChar *name);
294
295int xmlValidGetValidElements(xmlNode *prev,
296 xmlNode *next,
297 const xmlChar **list,
298 int max);
299int xmlValidGetPotentialChildren(xmlElementContent *ctree,
300 const xmlChar **list,
301 int *len,
302 int max);
Daniel Veillard9b731d72002-04-14 12:56:08 +0000303int xmlValidateNameValue (const xmlChar *value);
304int xmlValidateNamesValue (const xmlChar *value);
305int xmlValidateNmtokenValue (const xmlChar *value);
306int xmlValidateNmtokensValue(const xmlChar *value);
Daniel Veillard84d70a42002-09-16 10:51:38 +0000307
308#ifdef LIBXML_REGEXP_ENABLED
309/*
310 * Validation based on the regexp support
311 */
312int xmlValidBuildContentModel(xmlValidCtxtPtr ctxt,
313 xmlElementPtr elem);
314
315#endif /* LIBXML_REGEXP_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +0000316#ifdef __cplusplus
317}
318#endif
319#endif /* __XML_VALID_H__ */