blob: 54babdde6eb7909b16df4b7f04eda3f1fe4d9f6a [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 Veillard126f2792000-10-24 17:10:12 +000040 xmlDocPtr doc; /* the document */
41 int valid; /* temporary validity check result */
Daniel Veillard71b656e2000-01-05 14:46:17 +000042};
Daniel Veillardb05deb71999-08-10 19:04:08 +000043
Daniel Veillard3b9def11999-01-31 22:15:06 +000044/*
Daniel Veillard1e346af1999-02-22 10:33:01 +000045 * ALl notation declarations are stored in a table
46 * there is one table per DTD
47 */
48
Daniel Veillard126f2792000-10-24 17:10:12 +000049typedef struct _xmlHashTable xmlNotationTable;
Daniel Veillard71b656e2000-01-05 14:46:17 +000050typedef xmlNotationTable *xmlNotationTablePtr;
Daniel Veillard1e346af1999-02-22 10:33:01 +000051
52/*
Daniel Veillard3b9def11999-01-31 22:15:06 +000053 * ALl element declarations are stored in a table
54 * there is one table per DTD
55 */
56
Daniel Veillard126f2792000-10-24 17:10:12 +000057typedef struct _xmlHashTable xmlElementTable;
Daniel Veillard71b656e2000-01-05 14:46:17 +000058typedef xmlElementTable *xmlElementTablePtr;
Daniel Veillard3b9def11999-01-31 22:15:06 +000059
Daniel Veillard1e346af1999-02-22 10:33:01 +000060/*
61 * ALl attribute declarations are stored in a table
62 * there is one table per DTD
63 */
64
Daniel Veillard126f2792000-10-24 17:10:12 +000065typedef struct _xmlHashTable xmlAttributeTable;
Daniel Veillard71b656e2000-01-05 14:46:17 +000066typedef xmlAttributeTable *xmlAttributeTablePtr;
Daniel Veillard1e346af1999-02-22 10:33:01 +000067
Daniel Veillard991e63d1999-08-15 23:32:28 +000068/*
69 * ALl IDs attributes are stored in a table
70 * there is one table per document
71 */
72
Daniel Veillard126f2792000-10-24 17:10:12 +000073typedef struct _xmlHashTable xmlIDTable;
Daniel Veillard71b656e2000-01-05 14:46:17 +000074typedef xmlIDTable *xmlIDTablePtr;
Daniel Veillard991e63d1999-08-15 23:32:28 +000075
Daniel Veillardc08a2c61999-09-08 21:35:25 +000076/*
77 * ALl Refs attributes are stored in a table
78 * there is one table per document
79 */
80
Daniel Veillard126f2792000-10-24 17:10:12 +000081typedef struct _xmlHashTable xmlRefTable;
Daniel Veillard71b656e2000-01-05 14:46:17 +000082typedef xmlRefTable *xmlRefTablePtr;
Daniel Veillardc08a2c61999-09-08 21:35:25 +000083
Daniel Veillard1e346af1999-02-22 10:33:01 +000084/* Notation */
Daniel Veillardb96e6431999-08-29 21:02:19 +000085xmlNotationPtr xmlAddNotationDecl (xmlValidCtxtPtr ctxt,
86 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +000087 const xmlChar *name,
88 const xmlChar *PublicID,
89 const xmlChar *SystemID);
Daniel Veillard1e346af1999-02-22 10:33:01 +000090xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table);
Daniel Veillardb96e6431999-08-29 21:02:19 +000091void xmlFreeNotationTable(xmlNotationTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +000092void xmlDumpNotationDecl (xmlBufferPtr buf,
93 xmlNotationPtr nota);
Daniel Veillardb96e6431999-08-29 21:02:19 +000094void xmlDumpNotationTable(xmlBufferPtr buf,
95 xmlNotationTablePtr table);
Daniel Veillard1e346af1999-02-22 10:33:01 +000096
97/* Element Content */
Daniel Veillarddd6b3671999-09-23 22:19:22 +000098xmlElementContentPtr xmlNewElementContent (xmlChar *name,
Daniel Veillardc26087b1999-08-30 11:23:51 +000099 xmlElementContentType type);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000100xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000101void xmlFreeElementContent(xmlElementContentPtr cur);
Daniel Veillardcf461992000-03-14 18:30:20 +0000102void xmlSprintfElementContent(char *buf,
103 xmlElementContentPtr content,
104 int glob);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000105
106/* Element */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000107xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt,
108 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000109 const xmlChar *name,
Daniel Veillard51e3b151999-11-12 17:02:31 +0000110 xmlElementTypeVal type,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000111 xmlElementContentPtr content);
112xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table);
113void xmlFreeElementTable (xmlElementTablePtr table);
114void xmlDumpElementTable (xmlBufferPtr buf,
115 xmlElementTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000116void xmlDumpElementDecl (xmlBufferPtr buf,
117 xmlElementPtr elem);
Daniel Veillard3b9def11999-01-31 22:15:06 +0000118
Daniel Veillard1e346af1999-02-22 10:33:01 +0000119/* Enumeration */
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000120xmlEnumerationPtr xmlCreateEnumeration (xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000121void xmlFreeEnumeration (xmlEnumerationPtr cur);
122xmlEnumerationPtr xmlCopyEnumeration (xmlEnumerationPtr cur);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000123
124/* Attribute */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000125xmlAttributePtr xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,
126 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000127 const xmlChar *elem,
128 const xmlChar *name,
Daniel Veillard06047432000-04-24 11:33:38 +0000129 const xmlChar *ns,
Daniel Veillardc26087b1999-08-30 11:23:51 +0000130 xmlAttributeType type,
131 xmlAttributeDefault def,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000132 const xmlChar *defaultValue,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000133 xmlEnumerationPtr tree);
134xmlAttributeTablePtr xmlCopyAttributeTable (xmlAttributeTablePtr table);
135void xmlFreeAttributeTable (xmlAttributeTablePtr table);
136void xmlDumpAttributeTable (xmlBufferPtr buf,
137 xmlAttributeTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000138void xmlDumpAttributeDecl (xmlBufferPtr buf,
139 xmlAttributePtr attr);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000140
Daniel Veillard991e63d1999-08-15 23:32:28 +0000141/* IDs */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000142xmlIDPtr xmlAddID (xmlValidCtxtPtr ctxt,
143 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000144 const xmlChar *value,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000145 xmlAttrPtr attr);
146xmlIDTablePtr xmlCopyIDTable (xmlIDTablePtr table);
147void xmlFreeIDTable (xmlIDTablePtr table);
148xmlAttrPtr xmlGetID (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000149 const xmlChar *ID);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000150int xmlIsID (xmlDocPtr doc,
151 xmlNodePtr elem,
152 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000153int xmlRemoveID (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillard991e63d1999-08-15 23:32:28 +0000154
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000155/* IDREFs */
156xmlRefPtr xmlAddRef (xmlValidCtxtPtr ctxt,
157 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000158 const xmlChar *value,
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000159 xmlAttrPtr attr);
160xmlRefTablePtr xmlCopyRefTable (xmlRefTablePtr table);
161void xmlFreeRefTable (xmlRefTablePtr table);
162int xmlIsRef (xmlDocPtr doc,
163 xmlNodePtr elem,
164 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000165int xmlRemoveRef (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000166
Daniel Veillardb05deb71999-08-10 19:04:08 +0000167/**
168 * The public function calls related to validity checking
169 */
170
Daniel Veillardb96e6431999-08-29 21:02:19 +0000171int xmlValidateRoot (xmlValidCtxtPtr ctxt,
172 xmlDocPtr doc);
173int xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
174 xmlDocPtr doc,
175 xmlElementPtr elem);
Daniel Veillardcf461992000-03-14 18:30:20 +0000176xmlChar * xmlValidNormalizeAttributeValue(xmlDocPtr doc,
177 xmlNodePtr elem,
178 const xmlChar *name,
179 const xmlChar *value);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000180int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
181 xmlDocPtr doc,
182 xmlAttributePtr attr);
183int xmlValidateAttributeValue(xmlAttributeType type,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000184 const xmlChar *value);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000185int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
186 xmlDocPtr doc,
187 xmlNotationPtr nota);
188int xmlValidateDtd (xmlValidCtxtPtr ctxt,
189 xmlDocPtr doc,
190 xmlDtdPtr dtd);
Daniel Veillardcf461992000-03-14 18:30:20 +0000191int xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
192 xmlDocPtr doc);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000193int xmlValidateDocument (xmlValidCtxtPtr ctxt,
194 xmlDocPtr doc);
195int xmlValidateElement (xmlValidCtxtPtr ctxt,
196 xmlDocPtr doc,
197 xmlNodePtr elem);
198int xmlValidateOneElement (xmlValidCtxtPtr ctxt,
199 xmlDocPtr doc,
200 xmlNodePtr elem);
201int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
202 xmlDocPtr doc,
203 xmlNodePtr elem,
204 xmlAttrPtr attr,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000205 const xmlChar *value);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000206int xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
207 xmlDocPtr doc);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000208int xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
209 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000210 const xmlChar *notationName);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000211int xmlIsMixedElement (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000212 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000213xmlAttributePtr xmlGetDtdAttrDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000214 const xmlChar *elem,
215 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000216xmlNotationPtr xmlGetDtdNotationDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000217 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000218xmlElementPtr xmlGetDtdElementDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000219 const xmlChar *name);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000220
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000221int xmlValidGetValidElements(xmlNode *prev,
222 xmlNode *next,
223 const xmlChar **list,
224 int max);
225int xmlValidGetPotentialChildren(xmlElementContent *ctree,
226 const xmlChar **list,
227 int *len,
228 int max);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000229#ifdef __cplusplus
230}
231#endif
Daniel Veillard39a1f9a1999-01-17 19:11:59 +0000232#endif /* __XML_VALID_H__ */