valid.h 13.4 KB
Newer Older
1
/*
2 3
 * Summary: The DTD validation
 * Description: API for the DTD handling and the validity checking
4
 *
5
 * Copy: See Copyright for the status of this software.
6
 *
7
 * Author: Daniel Veillard
8 9 10 11 12 13
 */


#ifndef __XML_VALID_H__
#define __XML_VALID_H__

14
#include <libxml/xmlversion.h>
15
#include <libxml/xmlerror.h>
16
#include <libxml/tree.h>
17
#include <libxml/list.h>
18 19
#include <libxml/xmlautomata.h>
#include <libxml/xmlregexp.h>
20 21 22 23 24

#ifdef __cplusplus
extern "C" {
#endif

25
/*
26
 * Validation state added for non-determinist content model.
27 28 29 30
 */
typedef struct _xmlValidState xmlValidState;
typedef xmlValidState *xmlValidStatePtr;

31
/**
32
 * xmlValidityErrorFunc:
33 34 35
 * @ctx:  usually an xmlValidCtxtPtr to a validity error context,
 *        but comes from ctxt->userData (which normally contains such
 *        a pointer); ctxt->userData can be changed by the user.
36 37 38
 * @msg:  the string to format *printf like vararg
 * @...:  remaining arguments to the format
 *
39
 * Callback called when a validity error is found. This is a message
40
 * oriented function similar to an *printf function.
41
 */
42 43 44
typedef void (*xmlValidityErrorFunc) (void *ctx,
			     const char *msg,
			     ...);
45

46 47
/**
 * xmlValidityWarningFunc:
48 49 50
 * @ctx:  usually an xmlValidCtxtPtr to a validity error context,
 *        but comes from ctxt->userData (which normally contains such
 *        a pointer); ctxt->userData can be changed by the user.
51 52 53
 * @msg:  the string to format *printf like vararg
 * @...:  remaining arguments to the format
 *
54
 * Callback called when a validity warning is found. This is a message
55 56 57 58 59
 * oriented function similar to an *printf function.
 */
typedef void (*xmlValidityWarningFunc) (void *ctx,
			       const char *msg,
			       ...);
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#ifdef IN_LIBXML
/**
 * XML_CTXT_FINISH_DTD_0:
 *
 * Special value for finishDtd field when embedded in an xmlParserCtxt
 */
#define XML_CTXT_FINISH_DTD_0 0xabcd1234
/**
 * XML_CTXT_FINISH_DTD_1:
 *
 * Special value for finishDtd field when embedded in an xmlParserCtxt
 */
#define XML_CTXT_FINISH_DTD_1 0xabcd1235
#endif

76
/*
77
 * xmlValidCtxt:
78
 * An xmlValidCtxt is used for error reporting when validating.
79
 */
80 81 82 83 84 85 86 87 88 89 90 91 92
typedef struct _xmlValidCtxt xmlValidCtxt;
typedef xmlValidCtxt *xmlValidCtxtPtr;
struct _xmlValidCtxt {
    void *userData;			/* user specific data block */
    xmlValidityErrorFunc error;		/* the callback in case of errors */
    xmlValidityWarningFunc warning;	/* the callback in case of warning */

    /* Node analysis stack used when validating within entities */
    xmlNodePtr         node;          /* Current parsed Node */
    int                nodeNr;        /* Depth of the parsing stack */
    int                nodeMax;       /* Max depth of the parsing stack */
    xmlNodePtr        *nodeTab;       /* array of nodes */

93
    unsigned int     finishDtd;       /* finished validating the Dtd ? */
94 95
    xmlDocPtr              doc;       /* the document */
    int                  valid;       /* temporary validity check result */
96 97 98 99 100 101

    /* state state used for non-determinist content validation */
    xmlValidState     *vstate;        /* current state */
    int                vstateNr;      /* Depth of the validation stack */
    int                vstateMax;     /* Max depth of the validation stack */
    xmlValidState     *vstateTab;     /* array of validation states */
102 103 104 105 106 107 108 109

#ifdef LIBXML_REGEXP_ENABLED
    xmlAutomataPtr            am;     /* the automata */
    xmlAutomataStatePtr    state;     /* used to build the automata */
#else
    void                     *am;
    void                  *state;
#endif
110 111 112
};

/*
113 114
 * ALL notation declarations are stored in a table.
 * There is one table per DTD.
115 116 117 118 119 120
 */

typedef struct _xmlHashTable xmlNotationTable;
typedef xmlNotationTable *xmlNotationTablePtr;

/*
121 122
 * ALL element declarations are stored in a table.
 * There is one table per DTD.
123 124 125 126 127 128
 */

typedef struct _xmlHashTable xmlElementTable;
typedef xmlElementTable *xmlElementTablePtr;

/*
129 130
 * ALL attribute declarations are stored in a table.
 * There is one table per DTD.
131 132 133 134 135 136
 */

typedef struct _xmlHashTable xmlAttributeTable;
typedef xmlAttributeTable *xmlAttributeTablePtr;

/*
137 138
 * ALL IDs attributes are stored in a table.
 * There is one table per document.
139 140 141 142 143 144
 */

typedef struct _xmlHashTable xmlIDTable;
typedef xmlIDTable *xmlIDTablePtr;

/*
145 146
 * ALL Refs attributes are stored in a table.
 * There is one table per document.
147 148 149 150 151 152
 */

typedef struct _xmlHashTable xmlRefTable;
typedef xmlRefTable *xmlRefTablePtr;

/* Notation */
153 154
XMLPUBFUN xmlNotationPtr XMLCALL	    
		xmlAddNotationDecl	(xmlValidCtxtPtr ctxt,
155 156 157 158
					 xmlDtdPtr dtd,
					 const xmlChar *name,
					 const xmlChar *PublicID,
					 const xmlChar *SystemID);
159
#ifdef LIBXML_TREE_ENABLED
160 161
XMLPUBFUN xmlNotationTablePtr XMLCALL 
		xmlCopyNotationTable	(xmlNotationTablePtr table);
162
#endif /* LIBXML_TREE_ENABLED */
163 164
XMLPUBFUN void XMLCALL		    
		xmlFreeNotationTable	(xmlNotationTablePtr table);
165
#ifdef LIBXML_OUTPUT_ENABLED
166 167
XMLPUBFUN void XMLCALL		    
		xmlDumpNotationDecl	(xmlBufferPtr buf,
168
					 xmlNotationPtr nota);
169 170
XMLPUBFUN void XMLCALL		    
		xmlDumpNotationTable	(xmlBufferPtr buf,
171
					 xmlNotationTablePtr table);
172
#endif /* LIBXML_OUTPUT_ENABLED */
173 174

/* Element Content */
175
/* the non Doc version are being deprecated */
176 177 178 179 180 181 182
XMLPUBFUN xmlElementContentPtr XMLCALL 
		xmlNewElementContent	(const xmlChar *name,
					 xmlElementContentType type);
XMLPUBFUN xmlElementContentPtr XMLCALL 
		xmlCopyElementContent	(xmlElementContentPtr content);
XMLPUBFUN void XMLCALL		     
		xmlFreeElementContent	(xmlElementContentPtr cur);
183 184 185 186 187 188 189 190 191 192 193
/* the new versions with doc argument */
XMLPUBFUN xmlElementContentPtr XMLCALL 
		xmlNewDocElementContent	(xmlDocPtr doc,
					 const xmlChar *name,
					 xmlElementContentType type);
XMLPUBFUN xmlElementContentPtr XMLCALL 
		xmlCopyDocElementContent(xmlDocPtr doc,
					 xmlElementContentPtr content);
XMLPUBFUN void XMLCALL		     
		xmlFreeDocElementContent(xmlDocPtr doc,
					 xmlElementContentPtr cur);
194 195 196 197
XMLPUBFUN void XMLCALL		     
		xmlSnprintfElementContent(char *buf,
					 int size,
	                                 xmlElementContentPtr content,
198
					 int englob);
199
#ifdef LIBXML_OUTPUT_ENABLED
200
/* DEPRECATED */
201 202 203
XMLPUBFUN void XMLCALL		     
		xmlSprintfElementContent(char *buf,
	                                 xmlElementContentPtr content,
204
					 int englob);
205
#endif /* LIBXML_OUTPUT_ENABLED */
206
/* DEPRECATED */
207 208

/* Element */
209 210
XMLPUBFUN xmlElementPtr XMLCALL	   
		xmlAddElementDecl	(xmlValidCtxtPtr ctxt,
211 212 213 214
					 xmlDtdPtr dtd,
					 const xmlChar *name,
					 xmlElementTypeVal type,
					 xmlElementContentPtr content);
215
#ifdef LIBXML_TREE_ENABLED
216 217
XMLPUBFUN xmlElementTablePtr XMLCALL 
		xmlCopyElementTable	(xmlElementTablePtr table);
218
#endif /* LIBXML_TREE_ENABLED */
219 220
XMLPUBFUN void XMLCALL		   
		xmlFreeElementTable	(xmlElementTablePtr table);
221
#ifdef LIBXML_OUTPUT_ENABLED
222 223
XMLPUBFUN void XMLCALL		   
		xmlDumpElementTable	(xmlBufferPtr buf,
224
					 xmlElementTablePtr table);
225 226
XMLPUBFUN void XMLCALL		   
		xmlDumpElementDecl	(xmlBufferPtr buf,
227
					 xmlElementPtr elem);
228
#endif /* LIBXML_OUTPUT_ENABLED */
229 230

/* Enumeration */
231 232 233 234
XMLPUBFUN xmlEnumerationPtr XMLCALL 
		xmlCreateEnumeration	(const xmlChar *name);
XMLPUBFUN void XMLCALL		   
		xmlFreeEnumeration	(xmlEnumerationPtr cur);
235
#ifdef LIBXML_TREE_ENABLED
236 237
XMLPUBFUN xmlEnumerationPtr XMLCALL  
		xmlCopyEnumeration	(xmlEnumerationPtr cur);
238
#endif /* LIBXML_TREE_ENABLED */
239 240

/* Attribute */
241 242 243 244 245 246 247 248 249 250
XMLPUBFUN xmlAttributePtr XMLCALL	    
		xmlAddAttributeDecl	(xmlValidCtxtPtr ctxt,
					 xmlDtdPtr dtd,
					 const xmlChar *elem,
					 const xmlChar *name,
					 const xmlChar *ns,
					 xmlAttributeType type,
					 xmlAttributeDefault def,
					 const xmlChar *defaultValue,
					 xmlEnumerationPtr tree);
251
#ifdef LIBXML_TREE_ENABLED
252 253
XMLPUBFUN xmlAttributeTablePtr XMLCALL 
		xmlCopyAttributeTable  (xmlAttributeTablePtr table);
254
#endif /* LIBXML_TREE_ENABLED */
255 256
XMLPUBFUN void XMLCALL		     
		xmlFreeAttributeTable  (xmlAttributeTablePtr table);
257
#ifdef LIBXML_OUTPUT_ENABLED
258 259 260 261 262 263
XMLPUBFUN void XMLCALL		     
		xmlDumpAttributeTable  (xmlBufferPtr buf,
					xmlAttributeTablePtr table);
XMLPUBFUN void XMLCALL		     
		xmlDumpAttributeDecl   (xmlBufferPtr buf,
					xmlAttributePtr attr);
264
#endif /* LIBXML_OUTPUT_ENABLED */
265 266

/* IDs */
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
XMLPUBFUN xmlIDPtr XMLCALL	
		xmlAddID	       (xmlValidCtxtPtr ctxt,
					xmlDocPtr doc,
					const xmlChar *value,
					xmlAttrPtr attr);
XMLPUBFUN void XMLCALL		
		xmlFreeIDTable	       (xmlIDTablePtr table);
XMLPUBFUN xmlAttrPtr XMLCALL	
		xmlGetID	       (xmlDocPtr doc,
					const xmlChar *ID);
XMLPUBFUN int XMLCALL		
		xmlIsID		       (xmlDocPtr doc,
					xmlNodePtr elem,
					xmlAttrPtr attr);
XMLPUBFUN int XMLCALL		
		xmlRemoveID	       (xmlDocPtr doc, 
					xmlAttrPtr attr);
284 285

/* IDREFs */
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
XMLPUBFUN xmlRefPtr XMLCALL	
		xmlAddRef	       (xmlValidCtxtPtr ctxt,
					xmlDocPtr doc,
					const xmlChar *value,
					xmlAttrPtr attr);
XMLPUBFUN void XMLCALL		
		xmlFreeRefTable	       (xmlRefTablePtr table);
XMLPUBFUN int XMLCALL		
		xmlIsRef	       (xmlDocPtr doc,
					xmlNodePtr elem,
					xmlAttrPtr attr);
XMLPUBFUN int XMLCALL		
		xmlRemoveRef	       (xmlDocPtr doc, 
					xmlAttrPtr attr);
XMLPUBFUN xmlListPtr XMLCALL	
		xmlGetRefs	       (xmlDocPtr doc,
					const xmlChar *ID);
303 304

/**
305
 * The public function calls related to validity checking.
306
 */
307
#ifdef LIBXML_VALID_ENABLED
308 309 310 311 312 313
/* Allocate/Release Validation Contexts */
XMLPUBFUN xmlValidCtxtPtr XMLCALL	    
		xmlNewValidCtxt(void);
XMLPUBFUN void XMLCALL		    
		xmlFreeValidCtxt(xmlValidCtxtPtr);

314 315
XMLPUBFUN int XMLCALL		
		xmlValidateRoot		(xmlValidCtxtPtr ctxt,
316
					 xmlDocPtr doc);
317 318
XMLPUBFUN int XMLCALL		
		xmlValidateElementDecl	(xmlValidCtxtPtr ctxt,
319 320
					 xmlDocPtr doc,
		                         xmlElementPtr elem);
321 322
XMLPUBFUN xmlChar * XMLCALL	
		xmlValidNormalizeAttributeValue(xmlDocPtr doc,
323 324 325
					 xmlNodePtr elem,
					 const xmlChar *name,
					 const xmlChar *value);
326 327
XMLPUBFUN xmlChar * XMLCALL	
		xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt,
328
					 xmlDocPtr doc,
329 330 331
					 xmlNodePtr elem,
					 const xmlChar *name,
					 const xmlChar *value);
332 333
XMLPUBFUN int XMLCALL		
		xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
334 335
					 xmlDocPtr doc,
		                         xmlAttributePtr attr);
336 337
XMLPUBFUN int XMLCALL		
		xmlValidateAttributeValue(xmlAttributeType type,
338
					 const xmlChar *value);
339 340
XMLPUBFUN int XMLCALL		
		xmlValidateNotationDecl	(xmlValidCtxtPtr ctxt,
341 342
					 xmlDocPtr doc,
		                         xmlNotationPtr nota);
343 344
XMLPUBFUN int XMLCALL		
		xmlValidateDtd		(xmlValidCtxtPtr ctxt,
345 346
					 xmlDocPtr doc,
					 xmlDtdPtr dtd);
347 348
XMLPUBFUN int XMLCALL		
		xmlValidateDtdFinal	(xmlValidCtxtPtr ctxt,
349
					 xmlDocPtr doc);
350 351
XMLPUBFUN int XMLCALL		
		xmlValidateDocument	(xmlValidCtxtPtr ctxt,
352
					 xmlDocPtr doc);
353 354
XMLPUBFUN int XMLCALL		
		xmlValidateElement	(xmlValidCtxtPtr ctxt,
355 356
					 xmlDocPtr doc,
					 xmlNodePtr elem);
357 358
XMLPUBFUN int XMLCALL		
		xmlValidateOneElement	(xmlValidCtxtPtr ctxt,
359 360
					 xmlDocPtr doc,
		                         xmlNodePtr elem);
361 362
XMLPUBFUN int XMLCALL	
		xmlValidateOneAttribute	(xmlValidCtxtPtr ctxt,
363 364 365 366
					 xmlDocPtr doc,
					 xmlNodePtr	elem,
					 xmlAttrPtr attr,
					 const xmlChar *value);
367 368
XMLPUBFUN int XMLCALL		
		xmlValidateOneNamespace	(xmlValidCtxtPtr ctxt,
369 370 371 372 373
					 xmlDocPtr doc,
					 xmlNodePtr elem,
					 const xmlChar *prefix,
					 xmlNsPtr ns,
					 const xmlChar *value);
374 375
XMLPUBFUN int XMLCALL		
		xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
376
					 xmlDocPtr doc);
377 378 379
#endif /* LIBXML_VALID_ENABLED */

#if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
380 381
XMLPUBFUN int XMLCALL		
		xmlValidateNotationUse	(xmlValidCtxtPtr ctxt,
382 383
					 xmlDocPtr doc,
					 const xmlChar *notationName);
384
#endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */
385

386 387
XMLPUBFUN int XMLCALL		
		xmlIsMixedElement	(xmlDocPtr doc,
388
					 const xmlChar *name);
389 390
XMLPUBFUN xmlAttributePtr XMLCALL	
		xmlGetDtdAttrDesc	(xmlDtdPtr dtd,
391 392
					 const xmlChar *elem,
					 const xmlChar *name);
393 394
XMLPUBFUN xmlAttributePtr XMLCALL	
		xmlGetDtdQAttrDesc	(xmlDtdPtr dtd,
395 396 397
					 const xmlChar *elem,
					 const xmlChar *name,
					 const xmlChar *prefix);
398 399
XMLPUBFUN xmlNotationPtr XMLCALL	
		xmlGetDtdNotationDesc	(xmlDtdPtr dtd,
400
					 const xmlChar *name);
401 402
XMLPUBFUN xmlElementPtr XMLCALL	
		xmlGetDtdQElementDesc	(xmlDtdPtr dtd,
403 404
					 const xmlChar *name,
					 const xmlChar *prefix);
405 406
XMLPUBFUN xmlElementPtr XMLCALL	
		xmlGetDtdElementDesc	(xmlDtdPtr dtd,
407 408
					 const xmlChar *name);

409 410
#ifdef LIBXML_VALID_ENABLED

411 412
XMLPUBFUN int XMLCALL		
		xmlValidGetPotentialChildren(xmlElementContent *ctree,
413 414 415
					 const xmlChar **list,
					 int *len,
					 int max);
416

417 418 419 420 421
XMLPUBFUN int XMLCALL		
		xmlValidGetValidElements(xmlNode *prev,
					 xmlNode *next,
					 const xmlChar **names,
					 int max);
422 423 424 425 426 427 428 429
XMLPUBFUN int XMLCALL		
		xmlValidateNameValue	(const xmlChar *value);
XMLPUBFUN int XMLCALL		
		xmlValidateNamesValue	(const xmlChar *value);
XMLPUBFUN int XMLCALL		
		xmlValidateNmtokenValue	(const xmlChar *value);
XMLPUBFUN int XMLCALL		
		xmlValidateNmtokensValue(const xmlChar *value);
430 431 432 433 434

#ifdef LIBXML_REGEXP_ENABLED
/*
 * Validation based on the regexp support
 */
435 436
XMLPUBFUN int XMLCALL		
		xmlValidBuildContentModel(xmlValidCtxtPtr ctxt,
437 438
					 xmlElementPtr elem);

439 440
XMLPUBFUN int XMLCALL		
		xmlValidatePushElement	(xmlValidCtxtPtr ctxt,
441 442 443
					 xmlDocPtr doc,
					 xmlNodePtr elem,
					 const xmlChar *qname);
444 445
XMLPUBFUN int XMLCALL		
		xmlValidatePushCData	(xmlValidCtxtPtr ctxt,
446 447
					 const xmlChar *data,
					 int len);
448 449
XMLPUBFUN int XMLCALL		
		xmlValidatePopElement	(xmlValidCtxtPtr ctxt,
450 451 452
					 xmlDocPtr doc,
					 xmlNodePtr elem,
					 const xmlChar *qname);
453
#endif /* LIBXML_REGEXP_ENABLED */
454
#endif /* LIBXML_VALID_ENABLED */
455 456 457 458
#ifdef __cplusplus
}
#endif
#endif /* __XML_VALID_H__ */