blob: a7eb675d850cf5d27d62df30a3144603028af9b8 [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 Veillard389e6b72001-01-15 19:41:13 +000084/* helper */
85xmlChar * xmlSplitQName2 (const xmlChar *name,
86 xmlChar **prefix);
87
Daniel Veillard1e346af1999-02-22 10:33:01 +000088/* Notation */
Daniel Veillardb96e6431999-08-29 21:02:19 +000089xmlNotationPtr xmlAddNotationDecl (xmlValidCtxtPtr ctxt,
90 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +000091 const xmlChar *name,
92 const xmlChar *PublicID,
93 const xmlChar *SystemID);
Daniel Veillard1e346af1999-02-22 10:33:01 +000094xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table);
Daniel Veillardb96e6431999-08-29 21:02:19 +000095void xmlFreeNotationTable(xmlNotationTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +000096void xmlDumpNotationDecl (xmlBufferPtr buf,
97 xmlNotationPtr nota);
Daniel Veillardb96e6431999-08-29 21:02:19 +000098void xmlDumpNotationTable(xmlBufferPtr buf,
99 xmlNotationTablePtr table);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000100
101/* Element Content */
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000102xmlElementContentPtr xmlNewElementContent (xmlChar *name,
Daniel Veillardc26087b1999-08-30 11:23:51 +0000103 xmlElementContentType type);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000104xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000105void xmlFreeElementContent(xmlElementContentPtr cur);
Daniel Veillardcf461992000-03-14 18:30:20 +0000106void xmlSprintfElementContent(char *buf,
107 xmlElementContentPtr content,
108 int glob);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000109
110/* Element */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000111xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt,
112 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000113 const xmlChar *name,
Daniel Veillard51e3b151999-11-12 17:02:31 +0000114 xmlElementTypeVal type,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000115 xmlElementContentPtr content);
116xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table);
117void xmlFreeElementTable (xmlElementTablePtr table);
118void xmlDumpElementTable (xmlBufferPtr buf,
119 xmlElementTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000120void xmlDumpElementDecl (xmlBufferPtr buf,
121 xmlElementPtr elem);
Daniel Veillard3b9def11999-01-31 22:15:06 +0000122
Daniel Veillard1e346af1999-02-22 10:33:01 +0000123/* Enumeration */
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000124xmlEnumerationPtr xmlCreateEnumeration (xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000125void xmlFreeEnumeration (xmlEnumerationPtr cur);
126xmlEnumerationPtr xmlCopyEnumeration (xmlEnumerationPtr cur);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000127
128/* Attribute */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000129xmlAttributePtr xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,
130 xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000131 const xmlChar *elem,
132 const xmlChar *name,
Daniel Veillard06047432000-04-24 11:33:38 +0000133 const xmlChar *ns,
Daniel Veillardc26087b1999-08-30 11:23:51 +0000134 xmlAttributeType type,
135 xmlAttributeDefault def,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000136 const xmlChar *defaultValue,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000137 xmlEnumerationPtr tree);
138xmlAttributeTablePtr xmlCopyAttributeTable (xmlAttributeTablePtr table);
139void xmlFreeAttributeTable (xmlAttributeTablePtr table);
140void xmlDumpAttributeTable (xmlBufferPtr buf,
141 xmlAttributeTablePtr table);
Daniel Veillardcf461992000-03-14 18:30:20 +0000142void xmlDumpAttributeDecl (xmlBufferPtr buf,
143 xmlAttributePtr attr);
Daniel Veillard1e346af1999-02-22 10:33:01 +0000144
Daniel Veillard991e63d1999-08-15 23:32:28 +0000145/* IDs */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000146xmlIDPtr xmlAddID (xmlValidCtxtPtr ctxt,
147 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000148 const xmlChar *value,
Daniel Veillardb96e6431999-08-29 21:02:19 +0000149 xmlAttrPtr attr);
150xmlIDTablePtr xmlCopyIDTable (xmlIDTablePtr table);
151void xmlFreeIDTable (xmlIDTablePtr table);
152xmlAttrPtr xmlGetID (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000153 const xmlChar *ID);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000154int xmlIsID (xmlDocPtr doc,
155 xmlNodePtr elem,
156 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000157int xmlRemoveID (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillard991e63d1999-08-15 23:32:28 +0000158
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000159/* IDREFs */
160xmlRefPtr xmlAddRef (xmlValidCtxtPtr ctxt,
161 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000162 const xmlChar *value,
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000163 xmlAttrPtr attr);
164xmlRefTablePtr xmlCopyRefTable (xmlRefTablePtr table);
165void xmlFreeRefTable (xmlRefTablePtr table);
166int xmlIsRef (xmlDocPtr doc,
167 xmlNodePtr elem,
168 xmlAttrPtr attr);
Daniel Veillard71b656e2000-01-05 14:46:17 +0000169int xmlRemoveRef (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000170
Daniel Veillardb05deb71999-08-10 19:04:08 +0000171/**
172 * The public function calls related to validity checking
173 */
174
Daniel Veillardb96e6431999-08-29 21:02:19 +0000175int xmlValidateRoot (xmlValidCtxtPtr ctxt,
176 xmlDocPtr doc);
177int xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
178 xmlDocPtr doc,
179 xmlElementPtr elem);
Daniel Veillardcf461992000-03-14 18:30:20 +0000180xmlChar * xmlValidNormalizeAttributeValue(xmlDocPtr doc,
181 xmlNodePtr elem,
182 const xmlChar *name,
183 const xmlChar *value);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000184int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
185 xmlDocPtr doc,
186 xmlAttributePtr attr);
187int xmlValidateAttributeValue(xmlAttributeType type,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000188 const xmlChar *value);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000189int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
190 xmlDocPtr doc,
191 xmlNotationPtr nota);
192int xmlValidateDtd (xmlValidCtxtPtr ctxt,
193 xmlDocPtr doc,
194 xmlDtdPtr dtd);
Daniel Veillardcf461992000-03-14 18:30:20 +0000195int xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
196 xmlDocPtr doc);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000197int xmlValidateDocument (xmlValidCtxtPtr ctxt,
198 xmlDocPtr doc);
199int xmlValidateElement (xmlValidCtxtPtr ctxt,
200 xmlDocPtr doc,
201 xmlNodePtr elem);
202int xmlValidateOneElement (xmlValidCtxtPtr ctxt,
203 xmlDocPtr doc,
204 xmlNodePtr elem);
205int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
206 xmlDocPtr doc,
207 xmlNodePtr elem,
208 xmlAttrPtr attr,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000209 const xmlChar *value);
Daniel Veillardc08a2c61999-09-08 21:35:25 +0000210int xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
211 xmlDocPtr doc);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000212int xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
213 xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000214 const xmlChar *notationName);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000215int xmlIsMixedElement (xmlDocPtr doc,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000216 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000217xmlAttributePtr xmlGetDtdAttrDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000218 const xmlChar *elem,
219 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000220xmlNotationPtr xmlGetDtdNotationDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000221 const xmlChar *name);
Daniel Veillardb96e6431999-08-29 21:02:19 +0000222xmlElementPtr xmlGetDtdElementDesc (xmlDtdPtr dtd,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000223 const xmlChar *name);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000224
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000225int xmlValidGetValidElements(xmlNode *prev,
226 xmlNode *next,
227 const xmlChar **list,
228 int max);
229int xmlValidGetPotentialChildren(xmlElementContent *ctree,
230 const xmlChar **list,
231 int *len,
232 int max);
Daniel Veillardc26087b1999-08-30 11:23:51 +0000233#ifdef __cplusplus
234}
235#endif
Daniel Veillard39a1f9a1999-01-17 19:11:59 +0000236#endif /* __XML_VALID_H__ */