Debian Codegraph @

include/libxml/valid.h

raw
1 /**
2 * @file
3 *
4 * @brief DTD validator
5 *
6 * API to handle XML Document Type Definitions and validate
7 * documents.
8 *
9 * @copyright See Copyright for the status of this software.
10 *
11 * @author Daniel Veillard
12 */
13
14
15 #ifndef __XML_VALID_H__
16 #define __XML_VALID_H__
17
18 #include <libxml/xmlversion.h>
19 #include <libxml/xmlerror.h>
20 #define XML_TREE_INTERNALS
21 #include <libxml/tree.h>
22 #undef XML_TREE_INTERNALS
23 #include <libxml/list.h>
24 #include <libxml/xmlautomata.h>
25 #include <libxml/xmlregexp.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /*
32 * Validation state added for non-deterministic content model.
33 */
34 typedef struct _xmlValidState xmlValidState;
35 typedef xmlValidState *xmlValidStatePtr;
36
37 /**
38 * Report a validity error.
39 *
40 * @param ctx user data (usually an xmlValidCtxt)
41 * @param msg printf-like format string
42 * @param ... arguments to format
43 */
44 typedef void (*xmlValidityErrorFunc) (void *ctx,
45 const char *msg,
46 ...) LIBXML_ATTR_FORMAT(2,3);
47
48 /**
49 * Report a validity warning.
50 *
51 * @param ctx user data (usually an xmlValidCtxt)
52 * @param msg printf-like format string
53 * @param ... arguments to format
54 */
55 typedef void (*xmlValidityWarningFunc) (void *ctx,
56 const char *msg,
57 ...) LIBXML_ATTR_FORMAT(2,3);
58
59 typedef struct _xmlValidCtxt xmlValidCtxt;
60 typedef xmlValidCtxt *xmlValidCtxtPtr;
61 /**
62 * An xmlValidCtxt is used for error reporting when validating.
63 */
64 struct _xmlValidCtxt {
65 void *userData; /* user specific data block */
66 xmlValidityErrorFunc error; /* the callback in case of errors */
67 xmlValidityWarningFunc warning; /* the callback in case of warning */
68
69 /* Node analysis stack used when validating within entities */
70 xmlNode *node; /* Current parsed Node */
71 int nodeNr; /* Depth of the parsing stack */
72 int nodeMax; /* Max depth of the parsing stack */
73 xmlNode **nodeTab; /* array of nodes */
74
75 unsigned int flags; /* internal flags */
76 xmlDoc *doc; /* the document */
77 int valid; /* temporary validity check result */
78
79 /* state state used for non-determinist content validation */
80 xmlValidState *vstate; /* current state */
81 int vstateNr; /* Depth of the validation stack */
82 int vstateMax; /* Max depth of the validation stack */
83 xmlValidState *vstateTab; /* array of validation states */
84
85 #ifdef LIBXML_REGEXP_ENABLED
86 xmlAutomata *am; /* the automata */
87 xmlAutomataState *state; /* used to build the automata */
88 #else
89 void *am;
90 void *state;
91 #endif
92 };
93
94 typedef struct _xmlHashTable xmlNotationTable;
95 typedef xmlNotationTable *xmlNotationTablePtr;
96
97 typedef struct _xmlHashTable xmlElementTable;
98 typedef xmlElementTable *xmlElementTablePtr;
99
100 typedef struct _xmlHashTable xmlAttributeTable;
101 typedef xmlAttributeTable *xmlAttributeTablePtr;
102
103 typedef struct _xmlHashTable xmlIDTable;
104 typedef xmlIDTable *xmlIDTablePtr;
105
106 typedef struct _xmlHashTable xmlRefTable;
107 typedef xmlRefTable *xmlRefTablePtr;
108
109 /* Notation */
110 XMLPUBFUN xmlNotation *
111 xmlAddNotationDecl (xmlValidCtxt *ctxt,
112 xmlDtd *dtd,
113 const xmlChar *name,
114 const xmlChar *publicId,
115 const xmlChar *systemId);
116 XML_DEPRECATED
117 XMLPUBFUN xmlNotationTable *
118 xmlCopyNotationTable (xmlNotationTable *table);
119 XML_DEPRECATED
120 XMLPUBFUN void
121 xmlFreeNotationTable (xmlNotationTable *table);
122 #ifdef LIBXML_OUTPUT_ENABLED
123 XML_DEPRECATED
124 XMLPUBFUN void
125 xmlDumpNotationDecl (xmlBuffer *buf,
126 xmlNotation *nota);
127 /* XML_DEPRECATED, still used in lxml */
128 XMLPUBFUN void
129 xmlDumpNotationTable (xmlBuffer *buf,
130 xmlNotationTable *table);
131 #endif /* LIBXML_OUTPUT_ENABLED */
132
133 /* Element Content */
134 XML_DEPRECATED
135 XMLPUBFUN xmlElementContent *
136 xmlNewElementContent (const xmlChar *name,
137 xmlElementContentType type);
138 XML_DEPRECATED
139 XMLPUBFUN xmlElementContent *
140 xmlCopyElementContent (xmlElementContent *content);
141 XML_DEPRECATED
142 XMLPUBFUN void
143 xmlFreeElementContent (xmlElementContent *cur);
144 XML_DEPRECATED
145 XMLPUBFUN xmlElementContent *
146 xmlNewDocElementContent (xmlDoc *doc,
147 const xmlChar *name,
148 xmlElementContentType type);
149 XML_DEPRECATED
150 XMLPUBFUN xmlElementContent *
151 xmlCopyDocElementContent(xmlDoc *doc,
152 xmlElementContent *content);
153 XML_DEPRECATED
154 XMLPUBFUN void
155 xmlFreeDocElementContent(xmlDoc *doc,
156 xmlElementContent *cur);
157 XML_DEPRECATED
158 XMLPUBFUN void
159 xmlSnprintfElementContent(char *buf,
160 int size,
161 xmlElementContent *content,
162 int englob);
163 #ifdef LIBXML_OUTPUT_ENABLED
164 XML_DEPRECATED
165 XMLPUBFUN void
166 xmlSprintfElementContent(char *buf,
167 xmlElementContent *content,
168 int englob);
169 #endif /* LIBXML_OUTPUT_ENABLED */
170
171 /* Element */
172 XMLPUBFUN xmlElement *
173 xmlAddElementDecl (xmlValidCtxt *ctxt,
174 xmlDtd *dtd,
175 const xmlChar *name,
176 xmlElementTypeVal type,
177 xmlElementContent *content);
178 XML_DEPRECATED
179 XMLPUBFUN xmlElementTable *
180 xmlCopyElementTable (xmlElementTable *table);
181 XML_DEPRECATED
182 XMLPUBFUN void
183 xmlFreeElementTable (xmlElementTable *table);
184 #ifdef LIBXML_OUTPUT_ENABLED
185 XML_DEPRECATED
186 XMLPUBFUN void
187 xmlDumpElementTable (xmlBuffer *buf,
188 xmlElementTable *table);
189 XML_DEPRECATED
190 XMLPUBFUN void
191 xmlDumpElementDecl (xmlBuffer *buf,
192 xmlElement *elem);
193 #endif /* LIBXML_OUTPUT_ENABLED */
194
195 /* Enumeration */
196 XML_DEPRECATED
197 XMLPUBFUN xmlEnumeration *
198 xmlCreateEnumeration (const xmlChar *name);
199 /* XML_DEPRECATED, needed for custom attributeDecl SAX handler */
200 XMLPUBFUN void
201 xmlFreeEnumeration (xmlEnumeration *cur);
202 XML_DEPRECATED
203 XMLPUBFUN xmlEnumeration *
204 xmlCopyEnumeration (xmlEnumeration *cur);
205
206 /* Attribute */
207 XMLPUBFUN xmlAttribute *
208 xmlAddAttributeDecl (xmlValidCtxt *ctxt,
209 xmlDtd *dtd,
210 const xmlChar *elem,
211 const xmlChar *name,
212 const xmlChar *ns,
213 xmlAttributeType type,
214 xmlAttributeDefault def,
215 const xmlChar *defaultValue,
216 xmlEnumeration *tree);
217 XML_DEPRECATED
218 XMLPUBFUN xmlAttributeTable *
219 xmlCopyAttributeTable (xmlAttributeTable *table);
220 XML_DEPRECATED
221 XMLPUBFUN void
222 xmlFreeAttributeTable (xmlAttributeTable *table);
223 #ifdef LIBXML_OUTPUT_ENABLED
224 XML_DEPRECATED
225 XMLPUBFUN void
226 xmlDumpAttributeTable (xmlBuffer *buf,
227 xmlAttributeTable *table);
228 XML_DEPRECATED
229 XMLPUBFUN void
230 xmlDumpAttributeDecl (xmlBuffer *buf,
231 xmlAttribute *attr);
232 #endif /* LIBXML_OUTPUT_ENABLED */
233
234 /* IDs */
235 XMLPUBFUN int
236 xmlAddIDSafe (xmlAttr *attr,
237 const xmlChar *value);
238 XMLPUBFUN xmlID *
239 xmlAddID (xmlValidCtxt *ctxt,
240 xmlDoc *doc,
241 const xmlChar *value,
242 xmlAttr *attr);
243 XMLPUBFUN void
244 xmlFreeIDTable (xmlIDTable *table);
245 XMLPUBFUN xmlAttr *
246 xmlGetID (xmlDoc *doc,
247 const xmlChar *ID);
248 XMLPUBFUN int
249 xmlIsID (xmlDoc *doc,
250 xmlNode *elem,
251 xmlAttr *attr);
252 XMLPUBFUN int
253 xmlRemoveID (xmlDoc *doc,
254 xmlAttr *attr);
255
256 /* IDREFs */
257 XML_DEPRECATED
258 XMLPUBFUN xmlRef *
259 xmlAddRef (xmlValidCtxt *ctxt,
260 xmlDoc *doc,
261 const xmlChar *value,
262 xmlAttr *attr);
263 XML_DEPRECATED
264 XMLPUBFUN void
265 xmlFreeRefTable (xmlRefTable *table);
266 XML_DEPRECATED
267 XMLPUBFUN int
268 xmlIsRef (xmlDoc *doc,
269 xmlNode *elem,
270 xmlAttr *attr);
271 XML_DEPRECATED
272 XMLPUBFUN int
273 xmlRemoveRef (xmlDoc *doc,
274 xmlAttr *attr);
275 XML_DEPRECATED
276 XMLPUBFUN xmlList *
277 xmlGetRefs (xmlDoc *doc,
278 const xmlChar *ID);
279
280 /**
281 * The public function calls related to validity checking.
282 */
283 #ifdef LIBXML_VALID_ENABLED
284 /* Allocate/Release Validation Contexts */
285 XMLPUBFUN xmlValidCtxt *
286 xmlNewValidCtxt(void);
287 XMLPUBFUN void
288 xmlFreeValidCtxt(xmlValidCtxt *);
289
290 XML_DEPRECATED
291 XMLPUBFUN int
292 xmlValidateRoot (xmlValidCtxt *ctxt,
293 xmlDoc *doc);
294 XML_DEPRECATED
295 XMLPUBFUN int
296 xmlValidateElementDecl (xmlValidCtxt *ctxt,
297 xmlDoc *doc,
298 xmlElement *elem);
299 XML_DEPRECATED
300 XMLPUBFUN xmlChar *
301 xmlValidNormalizeAttributeValue(xmlDoc *doc,
302 xmlNode *elem,
303 const xmlChar *name,
304 const xmlChar *value);
305 XML_DEPRECATED
306 XMLPUBFUN xmlChar *
307 xmlValidCtxtNormalizeAttributeValue(xmlValidCtxt *ctxt,
308 xmlDoc *doc,
309 xmlNode *elem,
310 const xmlChar *name,
311 const xmlChar *value);
312 XML_DEPRECATED
313 XMLPUBFUN int
314 xmlValidateAttributeDecl(xmlValidCtxt *ctxt,
315 xmlDoc *doc,
316 xmlAttribute *attr);
317 XML_DEPRECATED
318 XMLPUBFUN int
319 xmlValidateAttributeValue(xmlAttributeType type,
320 const xmlChar *value);
321 XML_DEPRECATED
322 XMLPUBFUN int
323 xmlValidateNotationDecl (xmlValidCtxt *ctxt,
324 xmlDoc *doc,
325 xmlNotation *nota);
326 XMLPUBFUN int
327 xmlValidateDtd (xmlValidCtxt *ctxt,
328 xmlDoc *doc,
329 xmlDtd *dtd);
330 XML_DEPRECATED
331 XMLPUBFUN int
332 xmlValidateDtdFinal (xmlValidCtxt *ctxt,
333 xmlDoc *doc);
334 XMLPUBFUN int
335 xmlValidateDocument (xmlValidCtxt *ctxt,
336 xmlDoc *doc);
337 XMLPUBFUN int
338 xmlValidateElement (xmlValidCtxt *ctxt,
339 xmlDoc *doc,
340 xmlNode *elem);
341 XML_DEPRECATED
342 XMLPUBFUN int
343 xmlValidateOneElement (xmlValidCtxt *ctxt,
344 xmlDoc *doc,
345 xmlNode *elem);
346 XML_DEPRECATED
347 XMLPUBFUN int
348 xmlValidateOneAttribute (xmlValidCtxt *ctxt,
349 xmlDoc *doc,
350 xmlNode *elem,
351 xmlAttr *attr,
352 const xmlChar *value);
353 XML_DEPRECATED
354 XMLPUBFUN int
355 xmlValidateOneNamespace (xmlValidCtxt *ctxt,
356 xmlDoc *doc,
357 xmlNode *elem,
358 const xmlChar *prefix,
359 xmlNs *ns,
360 const xmlChar *value);
361 XML_DEPRECATED
362 XMLPUBFUN int
363 xmlValidateDocumentFinal(xmlValidCtxt *ctxt,
364 xmlDoc *doc);
365 XML_DEPRECATED
366 XMLPUBFUN int
367 xmlValidateNotationUse (xmlValidCtxt *ctxt,
368 xmlDoc *doc,
369 const xmlChar *notationName);
370 #endif /* LIBXML_VALID_ENABLED */
371
372 XML_DEPRECATED
373 XMLPUBFUN int
374 xmlIsMixedElement (xmlDoc *doc,
375 const xmlChar *name);
376 XMLPUBFUN xmlAttribute *
377 xmlGetDtdAttrDesc (xmlDtd *dtd,
378 const xmlChar *elem,
379 const xmlChar *name);
380 XMLPUBFUN xmlAttribute *
381 xmlGetDtdQAttrDesc (xmlDtd *dtd,
382 const xmlChar *elem,
383 const xmlChar *name,
384 const xmlChar *prefix);
385 XMLPUBFUN xmlNotation *
386 xmlGetDtdNotationDesc (xmlDtd *dtd,
387 const xmlChar *name);
388 XMLPUBFUN xmlElement *
389 xmlGetDtdQElementDesc (xmlDtd *dtd,
390 const xmlChar *name,
391 const xmlChar *prefix);
392 XMLPUBFUN xmlElement *
393 xmlGetDtdElementDesc (xmlDtd *dtd,
394 const xmlChar *name);
395
396 #ifdef LIBXML_VALID_ENABLED
397
398 XMLPUBFUN int
399 xmlValidGetPotentialChildren(xmlElementContent *ctree,
400 const xmlChar **names,
401 int *len,
402 int max);
403
404 /* only needed for `xmllint --insert` */
405 XMLPUBFUN int
406 xmlValidGetValidElements(xmlNode *prev,
407 xmlNode *next,
408 const xmlChar **names,
409 int max);
410 XMLPUBFUN int
411 xmlValidateNameValue (const xmlChar *value);
412 XMLPUBFUN int
413 xmlValidateNamesValue (const xmlChar *value);
414 XMLPUBFUN int
415 xmlValidateNmtokenValue (const xmlChar *value);
416 XMLPUBFUN int
417 xmlValidateNmtokensValue(const xmlChar *value);
418
419 #ifdef LIBXML_REGEXP_ENABLED
420 /*
421 * Validation based on the regexp support
422 */
423 XML_DEPRECATED
424 XMLPUBFUN int
425 xmlValidBuildContentModel(xmlValidCtxt *ctxt,
426 xmlElement *elem);
427
428 XML_DEPRECATED
429 XMLPUBFUN int
430 xmlValidatePushElement (xmlValidCtxt *ctxt,
431 xmlDoc *doc,
432 xmlNode *elem,
433 const xmlChar *qname);
434 XML_DEPRECATED
435 XMLPUBFUN int
436 xmlValidatePushCData (xmlValidCtxt *ctxt,
437 const xmlChar *data,
438 int len);
439 XML_DEPRECATED
440 XMLPUBFUN int
441 xmlValidatePopElement (xmlValidCtxt *ctxt,
442 xmlDoc *doc,
443 xmlNode *elem,
444 const xmlChar *qname);
445 #endif /* LIBXML_REGEXP_ENABLED */
446
447 #endif /* LIBXML_VALID_ENABLED */
448
449 #ifdef __cplusplus
450 }
451 #endif
452 #endif /* __XML_VALID_H__ */