codekingpro/portable-devtools
116k
1/*2 * Summary: The DTD validation3 * Description: API for the DTD handling and the validity checking4 *5 * Copy: See Copyright for the status of this software.6 *7 * Author: Daniel Veillard8 */9 10 11#ifndef __XML_VALID_H__12#define __XML_VALID_H__13 14#include <libxml/xmlversion.h>15#include <libxml/xmlerror.h>16#include <libxml/tree.h>17#include <libxml/list.h>18#include <libxml/xmlautomata.h>19#include <libxml/xmlregexp.h>20 21#ifdef __cplusplus22extern "C" {23#endif24 25/*26 * Validation state added for non-determinist content model.27 */28typedef struct _xmlValidState xmlValidState;29typedef xmlValidState *xmlValidStatePtr;30 31/**32 * xmlValidityErrorFunc:33 * @ctx: usually an xmlValidCtxtPtr to a validity error context,34 * but comes from ctxt->userData (which normally contains such35 * a pointer); ctxt->userData can be changed by the user.36 * @msg: the string to format *printf like vararg37 * @...: remaining arguments to the format38 *39 * Callback called when a validity error is found. This is a message40 * oriented function similar to an *printf function.41 */42typedef void (*xmlValidityErrorFunc) (void *ctx,43 const char *msg,44 ...) LIBXML_ATTR_FORMAT(2,3);45 46/**47 * xmlValidityWarningFunc:48 * @ctx: usually an xmlValidCtxtPtr to a validity error context,49 * but comes from ctxt->userData (which normally contains such50 * a pointer); ctxt->userData can be changed by the user.51 * @msg: the string to format *printf like vararg52 * @...: remaining arguments to the format53 *54 * Callback called when a validity warning is found. This is a message55 * oriented function similar to an *printf function.56 */57typedef void (*xmlValidityWarningFunc) (void *ctx,58 const char *msg,59 ...) LIBXML_ATTR_FORMAT(2,3);60 61/*62 * xmlValidCtxt:63 * An xmlValidCtxt is used for error reporting when validating.64 */65typedef struct _xmlValidCtxt xmlValidCtxt;66typedef xmlValidCtxt *xmlValidCtxtPtr;67struct _xmlValidCtxt {68 void *userData; /* user specific data block */69 xmlValidityErrorFunc error; /* the callback in case of errors */70 xmlValidityWarningFunc warning; /* the callback in case of warning */71 72 /* Node analysis stack used when validating within entities */73 xmlNodePtr node; /* Current parsed Node */74 int nodeNr; /* Depth of the parsing stack */75 int nodeMax; /* Max depth of the parsing stack */76 xmlNodePtr *nodeTab; /* array of nodes */77 78 unsigned int flags; /* internal flags */79 xmlDocPtr doc; /* the document */80 int valid; /* temporary validity check result */81 82 /* state state used for non-determinist content validation */83 xmlValidState *vstate; /* current state */84 int vstateNr; /* Depth of the validation stack */85 int vstateMax; /* Max depth of the validation stack */86 xmlValidState *vstateTab; /* array of validation states */87 88#ifdef LIBXML_REGEXP_ENABLED89 xmlAutomataPtr am; /* the automata */90 xmlAutomataStatePtr state; /* used to build the automata */91#else92 void *am;93 void *state;94#endif95};96 97/*98 * ALL notation declarations are stored in a table.99 * There is one table per DTD.100 */101 102typedef struct _xmlHashTable xmlNotationTable;103typedef xmlNotationTable *xmlNotationTablePtr;104 105/*106 * ALL element declarations are stored in a table.107 * There is one table per DTD.108 */109 110typedef struct _xmlHashTable xmlElementTable;111typedef xmlElementTable *xmlElementTablePtr;112 113/*114 * ALL attribute declarations are stored in a table.115 * There is one table per DTD.116 */117 118typedef struct _xmlHashTable xmlAttributeTable;119typedef xmlAttributeTable *xmlAttributeTablePtr;120 121/*122 * ALL IDs attributes are stored in a table.123 * There is one table per document.124 */125 126typedef struct _xmlHashTable xmlIDTable;127typedef xmlIDTable *xmlIDTablePtr;128 129/*130 * ALL Refs attributes are stored in a table.131 * There is one table per document.132 */133 134typedef struct _xmlHashTable xmlRefTable;135typedef xmlRefTable *xmlRefTablePtr;136 137/* Notation */138XMLPUBFUN xmlNotationPtr139 xmlAddNotationDecl (xmlValidCtxtPtr ctxt,140 xmlDtdPtr dtd,141 const xmlChar *name,142 const xmlChar *PublicID,143 const xmlChar *SystemID);144#ifdef LIBXML_TREE_ENABLED145XMLPUBFUN xmlNotationTablePtr146 xmlCopyNotationTable (xmlNotationTablePtr table);147#endif /* LIBXML_TREE_ENABLED */148XMLPUBFUN void149 xmlFreeNotationTable (xmlNotationTablePtr table);150#ifdef LIBXML_OUTPUT_ENABLED151XMLPUBFUN void152 xmlDumpNotationDecl (xmlBufferPtr buf,153 xmlNotationPtr nota);154XMLPUBFUN void155 xmlDumpNotationTable (xmlBufferPtr buf,156 xmlNotationTablePtr table);157#endif /* LIBXML_OUTPUT_ENABLED */158 159/* Element Content */160/* the non Doc version are being deprecated */161XMLPUBFUN xmlElementContentPtr162 xmlNewElementContent (const xmlChar *name,163 xmlElementContentType type);164XMLPUBFUN xmlElementContentPtr165 xmlCopyElementContent (xmlElementContentPtr content);166XMLPUBFUN void167 xmlFreeElementContent (xmlElementContentPtr cur);168/* the new versions with doc argument */169XMLPUBFUN xmlElementContentPtr170 xmlNewDocElementContent (xmlDocPtr doc,171 const xmlChar *name,172 xmlElementContentType type);173XMLPUBFUN xmlElementContentPtr174 xmlCopyDocElementContent(xmlDocPtr doc,175 xmlElementContentPtr content);176XMLPUBFUN void177 xmlFreeDocElementContent(xmlDocPtr doc,178 xmlElementContentPtr cur);179XMLPUBFUN void180 xmlSnprintfElementContent(char *buf,181 int size,182 xmlElementContentPtr content,183 int englob);184#ifdef LIBXML_OUTPUT_ENABLED185/* DEPRECATED */186XMLPUBFUN void187 xmlSprintfElementContent(char *buf,188 xmlElementContentPtr content,189 int englob);190#endif /* LIBXML_OUTPUT_ENABLED */191/* DEPRECATED */192 193/* Element */194XMLPUBFUN xmlElementPtr195 xmlAddElementDecl (xmlValidCtxtPtr ctxt,196 xmlDtdPtr dtd,197 const xmlChar *name,198 xmlElementTypeVal type,199 xmlElementContentPtr content);200#ifdef LIBXML_TREE_ENABLED201XMLPUBFUN xmlElementTablePtr202 xmlCopyElementTable (xmlElementTablePtr table);203#endif /* LIBXML_TREE_ENABLED */204XMLPUBFUN void205 xmlFreeElementTable (xmlElementTablePtr table);206#ifdef LIBXML_OUTPUT_ENABLED207XMLPUBFUN void208 xmlDumpElementTable (xmlBufferPtr buf,209 xmlElementTablePtr table);210XMLPUBFUN void211 xmlDumpElementDecl (xmlBufferPtr buf,212 xmlElementPtr elem);213#endif /* LIBXML_OUTPUT_ENABLED */214 215/* Enumeration */216XMLPUBFUN xmlEnumerationPtr217 xmlCreateEnumeration (const xmlChar *name);218XMLPUBFUN void219 xmlFreeEnumeration (xmlEnumerationPtr cur);220#ifdef LIBXML_TREE_ENABLED221XMLPUBFUN xmlEnumerationPtr222 xmlCopyEnumeration (xmlEnumerationPtr cur);223#endif /* LIBXML_TREE_ENABLED */224 225/* Attribute */226XMLPUBFUN xmlAttributePtr227 xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,228 xmlDtdPtr dtd,229 const xmlChar *elem,230 const xmlChar *name,231 const xmlChar *ns,232 xmlAttributeType type,233 xmlAttributeDefault def,234 const xmlChar *defaultValue,235 xmlEnumerationPtr tree);236#ifdef LIBXML_TREE_ENABLED237XMLPUBFUN xmlAttributeTablePtr238 xmlCopyAttributeTable (xmlAttributeTablePtr table);239#endif /* LIBXML_TREE_ENABLED */240XMLPUBFUN void241 xmlFreeAttributeTable (xmlAttributeTablePtr table);242#ifdef LIBXML_OUTPUT_ENABLED243XMLPUBFUN void244 xmlDumpAttributeTable (xmlBufferPtr buf,245 xmlAttributeTablePtr table);246XMLPUBFUN void247 xmlDumpAttributeDecl (xmlBufferPtr buf,248 xmlAttributePtr attr);249#endif /* LIBXML_OUTPUT_ENABLED */250 251/* IDs */252XMLPUBFUN xmlIDPtr253 xmlAddID (xmlValidCtxtPtr ctxt,254 xmlDocPtr doc,255 const xmlChar *value,256 xmlAttrPtr attr);257XMLPUBFUN void258 xmlFreeIDTable (xmlIDTablePtr table);259XMLPUBFUN xmlAttrPtr260 xmlGetID (xmlDocPtr doc,261 const xmlChar *ID);262XMLPUBFUN int263 xmlIsID (xmlDocPtr doc,264 xmlNodePtr elem,265 xmlAttrPtr attr);266XMLPUBFUN int267 xmlRemoveID (xmlDocPtr doc,268 xmlAttrPtr attr);269 270/* IDREFs */271XML_DEPRECATED272XMLPUBFUN xmlRefPtr273 xmlAddRef (xmlValidCtxtPtr ctxt,274 xmlDocPtr doc,275 const xmlChar *value,276 xmlAttrPtr attr);277XML_DEPRECATED278XMLPUBFUN void279 xmlFreeRefTable (xmlRefTablePtr table);280XML_DEPRECATED281XMLPUBFUN int282 xmlIsRef (xmlDocPtr doc,283 xmlNodePtr elem,284 xmlAttrPtr attr);285XML_DEPRECATED286XMLPUBFUN int287 xmlRemoveRef (xmlDocPtr doc,288 xmlAttrPtr attr);289XML_DEPRECATED290XMLPUBFUN xmlListPtr291 xmlGetRefs (xmlDocPtr doc,292 const xmlChar *ID);293 294/**295 * The public function calls related to validity checking.296 */297#ifdef LIBXML_VALID_ENABLED298/* Allocate/Release Validation Contexts */299XMLPUBFUN xmlValidCtxtPtr300 xmlNewValidCtxt(void);301XMLPUBFUN void302 xmlFreeValidCtxt(xmlValidCtxtPtr);303 304XMLPUBFUN int305 xmlValidateRoot (xmlValidCtxtPtr ctxt,306 xmlDocPtr doc);307XMLPUBFUN int308 xmlValidateElementDecl (xmlValidCtxtPtr ctxt,309 xmlDocPtr doc,310 xmlElementPtr elem);311XMLPUBFUN xmlChar *312 xmlValidNormalizeAttributeValue(xmlDocPtr doc,313 xmlNodePtr elem,314 const xmlChar *name,315 const xmlChar *value);316XMLPUBFUN xmlChar *317 xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt,318 xmlDocPtr doc,319 xmlNodePtr elem,320 const xmlChar *name,321 const xmlChar *value);322XMLPUBFUN int323 xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,324 xmlDocPtr doc,325 xmlAttributePtr attr);326XMLPUBFUN int327 xmlValidateAttributeValue(xmlAttributeType type,328 const xmlChar *value);329XMLPUBFUN int330 xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,331 xmlDocPtr doc,332 xmlNotationPtr nota);333XMLPUBFUN int334 xmlValidateDtd (xmlValidCtxtPtr ctxt,335 xmlDocPtr doc,336 xmlDtdPtr dtd);337XMLPUBFUN int338 xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,339 xmlDocPtr doc);340XMLPUBFUN int341 xmlValidateDocument (xmlValidCtxtPtr ctxt,342 xmlDocPtr doc);343XMLPUBFUN int344 xmlValidateElement (xmlValidCtxtPtr ctxt,345 xmlDocPtr doc,346 xmlNodePtr elem);347XMLPUBFUN int348 xmlValidateOneElement (xmlValidCtxtPtr ctxt,349 xmlDocPtr doc,350 xmlNodePtr elem);351XMLPUBFUN int352 xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,353 xmlDocPtr doc,354 xmlNodePtr elem,355 xmlAttrPtr attr,356 const xmlChar *value);357XMLPUBFUN int358 xmlValidateOneNamespace (xmlValidCtxtPtr ctxt,359 xmlDocPtr doc,360 xmlNodePtr elem,361 const xmlChar *prefix,362 xmlNsPtr ns,363 const xmlChar *value);364XMLPUBFUN int365 xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,366 xmlDocPtr doc);367#endif /* LIBXML_VALID_ENABLED */368 369#if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)370XMLPUBFUN int371 xmlValidateNotationUse (xmlValidCtxtPtr ctxt,372 xmlDocPtr doc,373 const xmlChar *notationName);374#endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */375 376XMLPUBFUN int377 xmlIsMixedElement (xmlDocPtr doc,378 const xmlChar *name);379XMLPUBFUN xmlAttributePtr380 xmlGetDtdAttrDesc (xmlDtdPtr dtd,381 const xmlChar *elem,382 const xmlChar *name);383XMLPUBFUN xmlAttributePtr384 xmlGetDtdQAttrDesc (xmlDtdPtr dtd,385 const xmlChar *elem,386 const xmlChar *name,387 const xmlChar *prefix);388XMLPUBFUN xmlNotationPtr389 xmlGetDtdNotationDesc (xmlDtdPtr dtd,390 const xmlChar *name);391XMLPUBFUN xmlElementPtr392 xmlGetDtdQElementDesc (xmlDtdPtr dtd,393 const xmlChar *name,394 const xmlChar *prefix);395XMLPUBFUN xmlElementPtr396 xmlGetDtdElementDesc (xmlDtdPtr dtd,397 const xmlChar *name);398 399#ifdef LIBXML_VALID_ENABLED400 401XMLPUBFUN int402 xmlValidGetPotentialChildren(xmlElementContent *ctree,403 const xmlChar **names,404 int *len,405 int max);406 407XMLPUBFUN int408 xmlValidGetValidElements(xmlNode *prev,409 xmlNode *next,410 const xmlChar **names,411 int max);412XMLPUBFUN int413 xmlValidateNameValue (const xmlChar *value);414XMLPUBFUN int415 xmlValidateNamesValue (const xmlChar *value);416XMLPUBFUN int417 xmlValidateNmtokenValue (const xmlChar *value);418XMLPUBFUN int419 xmlValidateNmtokensValue(const xmlChar *value);420 421#ifdef LIBXML_REGEXP_ENABLED422/*423 * Validation based on the regexp support424 */425XMLPUBFUN int426 xmlValidBuildContentModel(xmlValidCtxtPtr ctxt,427 xmlElementPtr elem);428 429XMLPUBFUN int430 xmlValidatePushElement (xmlValidCtxtPtr ctxt,431 xmlDocPtr doc,432 xmlNodePtr elem,433 const xmlChar *qname);434XMLPUBFUN int435 xmlValidatePushCData (xmlValidCtxtPtr ctxt,436 const xmlChar *data,437 int len);438XMLPUBFUN int439 xmlValidatePopElement (xmlValidCtxtPtr ctxt,440 xmlDocPtr doc,441 xmlNodePtr elem,442 const xmlChar *qname);443#endif /* LIBXML_REGEXP_ENABLED */444#endif /* LIBXML_VALID_ENABLED */445#ifdef __cplusplus446}447#endif448#endif /* __XML_VALID_H__ */449 