blob: c048ba0e302e8861d060e4213a2cc5ad480741cb [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 *
6 * Daniel.Veillard@w3.org
7 */
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>
Owen Taylor3473f882001-02-23 17:55:21 +000015
16#ifdef __cplusplus
17extern "C" {
18#endif
19
Daniel Veillarddab4cb32001-04-20 13:03:48 +000020/*
21 * Validation state added for non-determinist content model
22 */
23typedef struct _xmlValidState xmlValidState;
24typedef xmlValidState *xmlValidStatePtr;
25
Owen Taylor3473f882001-02-23 17:55:21 +000026/**
27 * an xmlValidCtxt is used for error reporting when validating
28 */
29
30typedef void (*xmlValidityErrorFunc) (void *ctx, const char *msg, ...);
31typedef void (*xmlValidityWarningFunc) (void *ctx, const char *msg, ...);
32
33typedef struct _xmlValidCtxt xmlValidCtxt;
34typedef xmlValidCtxt *xmlValidCtxtPtr;
35struct _xmlValidCtxt {
36 void *userData; /* user specific data block */
37 xmlValidityErrorFunc error; /* the callback in case of errors */
38 xmlValidityWarningFunc warning; /* the callback in case of warning */
39
40 /* Node analysis stack used when validating within entities */
41 xmlNodePtr node; /* Current parsed Node */
42 int nodeNr; /* Depth of the parsing stack */
43 int nodeMax; /* Max depth of the parsing stack */
44 xmlNodePtr *nodeTab; /* array of nodes */
45
46 int finishDtd; /* finished validating the Dtd ? */
47 xmlDocPtr doc; /* the document */
48 int valid; /* temporary validity check result */
Daniel Veillarddab4cb32001-04-20 13:03:48 +000049
50 /* state state used for non-determinist content validation */
51 xmlValidState *vstate; /* current state */
52 int vstateNr; /* Depth of the validation stack */
53 int vstateMax; /* Max depth of the validation stack */
54 xmlValidState *vstateTab; /* array of validation states */
Owen Taylor3473f882001-02-23 17:55:21 +000055};
56
57/*
58 * ALl notation declarations are stored in a table
59 * there is one table per DTD
60 */
61
62typedef struct _xmlHashTable xmlNotationTable;
63typedef xmlNotationTable *xmlNotationTablePtr;
64
65/*
66 * ALl element declarations are stored in a table
67 * there is one table per DTD
68 */
69
70typedef struct _xmlHashTable xmlElementTable;
71typedef xmlElementTable *xmlElementTablePtr;
72
73/*
74 * ALl attribute declarations are stored in a table
75 * there is one table per DTD
76 */
77
78typedef struct _xmlHashTable xmlAttributeTable;
79typedef xmlAttributeTable *xmlAttributeTablePtr;
80
81/*
82 * ALl IDs attributes are stored in a table
83 * there is one table per document
84 */
85
86typedef struct _xmlHashTable xmlIDTable;
87typedef xmlIDTable *xmlIDTablePtr;
88
89/*
90 * ALl Refs attributes are stored in a table
91 * there is one table per document
92 */
93
94typedef struct _xmlHashTable xmlRefTable;
95typedef xmlRefTable *xmlRefTablePtr;
96
97/* helper */
98xmlChar * xmlSplitQName2 (const xmlChar *name,
99 xmlChar **prefix);
100
101/* Notation */
102xmlNotationPtr xmlAddNotationDecl (xmlValidCtxtPtr ctxt,
103 xmlDtdPtr dtd,
104 const xmlChar *name,
105 const xmlChar *PublicID,
106 const xmlChar *SystemID);
107xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table);
108void xmlFreeNotationTable(xmlNotationTablePtr table);
109void xmlDumpNotationDecl (xmlBufferPtr buf,
110 xmlNotationPtr nota);
111void xmlDumpNotationTable(xmlBufferPtr buf,
112 xmlNotationTablePtr table);
113
114/* Element Content */
115xmlElementContentPtr xmlNewElementContent (xmlChar *name,
116 xmlElementContentType type);
117xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
118void xmlFreeElementContent(xmlElementContentPtr cur);
119void xmlSprintfElementContent(char *buf,
120 xmlElementContentPtr content,
121 int glob);
122
123/* Element */
124xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt,
125 xmlDtdPtr dtd,
126 const xmlChar *name,
127 xmlElementTypeVal type,
128 xmlElementContentPtr content);
129xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table);
130void xmlFreeElementTable (xmlElementTablePtr table);
131void xmlDumpElementTable (xmlBufferPtr buf,
132 xmlElementTablePtr table);
133void xmlDumpElementDecl (xmlBufferPtr buf,
134 xmlElementPtr elem);
135
136/* Enumeration */
137xmlEnumerationPtr xmlCreateEnumeration (xmlChar *name);
138void xmlFreeEnumeration (xmlEnumerationPtr cur);
139xmlEnumerationPtr xmlCopyEnumeration (xmlEnumerationPtr cur);
140
141/* Attribute */
142xmlAttributePtr xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,
143 xmlDtdPtr dtd,
144 const xmlChar *elem,
145 const xmlChar *name,
146 const xmlChar *ns,
147 xmlAttributeType type,
148 xmlAttributeDefault def,
149 const xmlChar *defaultValue,
150 xmlEnumerationPtr tree);
151xmlAttributeTablePtr xmlCopyAttributeTable (xmlAttributeTablePtr table);
152void xmlFreeAttributeTable (xmlAttributeTablePtr table);
153void xmlDumpAttributeTable (xmlBufferPtr buf,
154 xmlAttributeTablePtr table);
155void xmlDumpAttributeDecl (xmlBufferPtr buf,
156 xmlAttributePtr attr);
157
158/* IDs */
159xmlIDPtr xmlAddID (xmlValidCtxtPtr ctxt,
160 xmlDocPtr doc,
161 const xmlChar *value,
162 xmlAttrPtr attr);
163xmlIDTablePtr xmlCopyIDTable (xmlIDTablePtr table);
164void xmlFreeIDTable (xmlIDTablePtr table);
165xmlAttrPtr xmlGetID (xmlDocPtr doc,
166 const xmlChar *ID);
167int xmlIsID (xmlDocPtr doc,
168 xmlNodePtr elem,
169 xmlAttrPtr attr);
170int xmlRemoveID (xmlDocPtr doc, xmlAttrPtr attr);
171
172/* IDREFs */
173xmlRefPtr xmlAddRef (xmlValidCtxtPtr ctxt,
174 xmlDocPtr doc,
175 const xmlChar *value,
176 xmlAttrPtr attr);
177xmlRefTablePtr xmlCopyRefTable (xmlRefTablePtr table);
178void xmlFreeRefTable (xmlRefTablePtr table);
179int xmlIsRef (xmlDocPtr doc,
180 xmlNodePtr elem,
181 xmlAttrPtr attr);
182int xmlRemoveRef (xmlDocPtr doc, xmlAttrPtr attr);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000183xmlListPtr xmlGetRefs (xmlDocPtr doc,
184 const xmlChar *ID);
Owen Taylor3473f882001-02-23 17:55:21 +0000185
186/**
187 * The public function calls related to validity checking
188 */
189
190int xmlValidateRoot (xmlValidCtxtPtr ctxt,
191 xmlDocPtr doc);
192int xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
193 xmlDocPtr doc,
194 xmlElementPtr elem);
195xmlChar * xmlValidNormalizeAttributeValue(xmlDocPtr doc,
196 xmlNodePtr elem,
197 const xmlChar *name,
198 const xmlChar *value);
199int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
200 xmlDocPtr doc,
201 xmlAttributePtr attr);
202int xmlValidateAttributeValue(xmlAttributeType type,
203 const xmlChar *value);
204int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
205 xmlDocPtr doc,
206 xmlNotationPtr nota);
207int xmlValidateDtd (xmlValidCtxtPtr ctxt,
208 xmlDocPtr doc,
209 xmlDtdPtr dtd);
210int xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
211 xmlDocPtr doc);
212int xmlValidateDocument (xmlValidCtxtPtr ctxt,
213 xmlDocPtr doc);
214int xmlValidateElement (xmlValidCtxtPtr ctxt,
215 xmlDocPtr doc,
216 xmlNodePtr elem);
217int xmlValidateOneElement (xmlValidCtxtPtr ctxt,
218 xmlDocPtr doc,
219 xmlNodePtr elem);
220int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
221 xmlDocPtr doc,
222 xmlNodePtr elem,
223 xmlAttrPtr attr,
224 const xmlChar *value);
225int xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
226 xmlDocPtr doc);
227int xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
228 xmlDocPtr doc,
229 const xmlChar *notationName);
230int xmlIsMixedElement (xmlDocPtr doc,
231 const xmlChar *name);
232xmlAttributePtr xmlGetDtdAttrDesc (xmlDtdPtr dtd,
233 const xmlChar *elem,
234 const xmlChar *name);
235xmlNotationPtr xmlGetDtdNotationDesc (xmlDtdPtr dtd,
236 const xmlChar *name);
237xmlElementPtr xmlGetDtdElementDesc (xmlDtdPtr dtd,
238 const xmlChar *name);
239
240int xmlValidGetValidElements(xmlNode *prev,
241 xmlNode *next,
242 const xmlChar **list,
243 int max);
244int xmlValidGetPotentialChildren(xmlElementContent *ctree,
245 const xmlChar **list,
246 int *len,
247 int max);
248#ifdef __cplusplus
249}
250#endif
251#endif /* __XML_VALID_H__ */