Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-25 09:20:38

0001 /**
0002  * @file
0003  * 
0004  * @brief DTD validator
0005  * 
0006  * API to handle XML Document Type Definitions and validate
0007  * documents.
0008  *
0009  * @copyright See Copyright for the status of this software.
0010  *
0011  * @author Daniel Veillard
0012  */
0013 
0014 
0015 #ifndef __XML_VALID_H__
0016 #define __XML_VALID_H__
0017 
0018 #include <libxml/xmlversion.h>
0019 #include <libxml/xmlerror.h>
0020 #define XML_TREE_INTERNALS
0021 #include <libxml/tree.h>
0022 #undef XML_TREE_INTERNALS
0023 #include <libxml/list.h>
0024 #include <libxml/xmlautomata.h>
0025 #include <libxml/xmlregexp.h>
0026 
0027 #ifdef __cplusplus
0028 extern "C" {
0029 #endif
0030 
0031 /*
0032  * Validation state added for non-deterministic content model.
0033  */
0034 typedef struct _xmlValidState xmlValidState;
0035 typedef xmlValidState *xmlValidStatePtr;
0036 
0037 /**
0038  * Report a validity error.
0039  *
0040  * @param ctx  user data (usually an xmlValidCtxt)
0041  * @param msg  printf-like format string
0042  * @param ...  arguments to format
0043  */
0044 typedef void (*xmlValidityErrorFunc) (void *ctx,
0045                  const char *msg,
0046                  ...) LIBXML_ATTR_FORMAT(2,3);
0047 
0048 /**
0049  * Report a validity warning.
0050  *
0051  * @param ctx  user data (usually an xmlValidCtxt)
0052  * @param msg  printf-like format string
0053  * @param ...  arguments to format
0054  */
0055 typedef void (*xmlValidityWarningFunc) (void *ctx,
0056                    const char *msg,
0057                    ...) LIBXML_ATTR_FORMAT(2,3);
0058 
0059 typedef struct _xmlValidCtxt xmlValidCtxt;
0060 typedef xmlValidCtxt *xmlValidCtxtPtr;
0061 /**
0062  * An xmlValidCtxt is used for error reporting when validating.
0063  */
0064 struct _xmlValidCtxt {
0065     void *userData;         /* user specific data block */
0066     xmlValidityErrorFunc error;     /* the callback in case of errors */
0067     xmlValidityWarningFunc warning; /* the callback in case of warning */
0068 
0069     /* Node analysis stack used when validating within entities */
0070     xmlNode           *node;          /* Current parsed Node */
0071     int                nodeNr;        /* Depth of the parsing stack */
0072     int                nodeMax;       /* Max depth of the parsing stack */
0073     xmlNode          **nodeTab;       /* array of nodes */
0074 
0075     unsigned int         flags;       /* internal flags */
0076     xmlDoc                *doc;       /* the document */
0077     int                  valid;       /* temporary validity check result */
0078 
0079     /* state state used for non-determinist content validation */
0080     xmlValidState     *vstate;        /* current state */
0081     int                vstateNr;      /* Depth of the validation stack */
0082     int                vstateMax;     /* Max depth of the validation stack */
0083     xmlValidState     *vstateTab;     /* array of validation states */
0084 
0085 #ifdef LIBXML_REGEXP_ENABLED
0086     xmlAutomata              *am;     /* the automata */
0087     xmlAutomataState      *state;     /* used to build the automata */
0088 #else
0089     void                     *am;
0090     void                  *state;
0091 #endif
0092 };
0093 
0094 typedef struct _xmlHashTable xmlNotationTable;
0095 typedef xmlNotationTable *xmlNotationTablePtr;
0096 
0097 typedef struct _xmlHashTable xmlElementTable;
0098 typedef xmlElementTable *xmlElementTablePtr;
0099 
0100 typedef struct _xmlHashTable xmlAttributeTable;
0101 typedef xmlAttributeTable *xmlAttributeTablePtr;
0102 
0103 typedef struct _xmlHashTable xmlIDTable;
0104 typedef xmlIDTable *xmlIDTablePtr;
0105 
0106 typedef struct _xmlHashTable xmlRefTable;
0107 typedef xmlRefTable *xmlRefTablePtr;
0108 
0109 /* Notation */
0110 XMLPUBFUN xmlNotation *
0111         xmlAddNotationDecl  (xmlValidCtxt *ctxt,
0112                      xmlDtd *dtd,
0113                      const xmlChar *name,
0114                      const xmlChar *publicId,
0115                      const xmlChar *systemId);
0116 XML_DEPRECATED
0117 XMLPUBFUN xmlNotationTable *
0118         xmlCopyNotationTable    (xmlNotationTable *table);
0119 XML_DEPRECATED
0120 XMLPUBFUN void
0121         xmlFreeNotationTable    (xmlNotationTable *table);
0122 #ifdef LIBXML_OUTPUT_ENABLED
0123 XML_DEPRECATED
0124 XMLPUBFUN void
0125         xmlDumpNotationDecl (xmlBuffer *buf,
0126                      xmlNotation *nota);
0127 /* XML_DEPRECATED, still used in lxml */
0128 XMLPUBFUN void
0129         xmlDumpNotationTable    (xmlBuffer *buf,
0130                      xmlNotationTable *table);
0131 #endif /* LIBXML_OUTPUT_ENABLED */
0132 
0133 /* Element Content */
0134 XML_DEPRECATED
0135 XMLPUBFUN xmlElementContent *
0136         xmlNewElementContent    (const xmlChar *name,
0137                      xmlElementContentType type);
0138 XML_DEPRECATED
0139 XMLPUBFUN xmlElementContent *
0140         xmlCopyElementContent   (xmlElementContent *content);
0141 XML_DEPRECATED
0142 XMLPUBFUN void
0143         xmlFreeElementContent   (xmlElementContent *cur);
0144 XML_DEPRECATED
0145 XMLPUBFUN xmlElementContent *
0146         xmlNewDocElementContent (xmlDoc *doc,
0147                      const xmlChar *name,
0148                      xmlElementContentType type);
0149 XML_DEPRECATED
0150 XMLPUBFUN xmlElementContent *
0151         xmlCopyDocElementContent(xmlDoc *doc,
0152                      xmlElementContent *content);
0153 XML_DEPRECATED
0154 XMLPUBFUN void
0155         xmlFreeDocElementContent(xmlDoc *doc,
0156                      xmlElementContent *cur);
0157 XML_DEPRECATED
0158 XMLPUBFUN void
0159         xmlSnprintfElementContent(char *buf,
0160                      int size,
0161                                      xmlElementContent *content,
0162                      int englob);
0163 #ifdef LIBXML_OUTPUT_ENABLED
0164 XML_DEPRECATED
0165 XMLPUBFUN void
0166         xmlSprintfElementContent(char *buf,
0167                                      xmlElementContent *content,
0168                      int englob);
0169 #endif /* LIBXML_OUTPUT_ENABLED */
0170 
0171 /* Element */
0172 XMLPUBFUN xmlElement *
0173         xmlAddElementDecl   (xmlValidCtxt *ctxt,
0174                      xmlDtd *dtd,
0175                      const xmlChar *name,
0176                      xmlElementTypeVal type,
0177                      xmlElementContent *content);
0178 XML_DEPRECATED
0179 XMLPUBFUN xmlElementTable *
0180         xmlCopyElementTable (xmlElementTable *table);
0181 XML_DEPRECATED
0182 XMLPUBFUN void
0183         xmlFreeElementTable (xmlElementTable *table);
0184 #ifdef LIBXML_OUTPUT_ENABLED
0185 XML_DEPRECATED
0186 XMLPUBFUN void
0187         xmlDumpElementTable (xmlBuffer *buf,
0188                      xmlElementTable *table);
0189 XML_DEPRECATED
0190 XMLPUBFUN void
0191         xmlDumpElementDecl  (xmlBuffer *buf,
0192                      xmlElement *elem);
0193 #endif /* LIBXML_OUTPUT_ENABLED */
0194 
0195 /* Enumeration */
0196 XML_DEPRECATED
0197 XMLPUBFUN xmlEnumeration *
0198         xmlCreateEnumeration    (const xmlChar *name);
0199 /* XML_DEPRECATED, needed for custom attributeDecl SAX handler */
0200 XMLPUBFUN void
0201         xmlFreeEnumeration  (xmlEnumeration *cur);
0202 XML_DEPRECATED
0203 XMLPUBFUN xmlEnumeration *
0204         xmlCopyEnumeration  (xmlEnumeration *cur);
0205 
0206 /* Attribute */
0207 XMLPUBFUN xmlAttribute *
0208         xmlAddAttributeDecl (xmlValidCtxt *ctxt,
0209                      xmlDtd *dtd,
0210                      const xmlChar *elem,
0211                      const xmlChar *name,
0212                      const xmlChar *ns,
0213                      xmlAttributeType type,
0214                      xmlAttributeDefault def,
0215                      const xmlChar *defaultValue,
0216                      xmlEnumeration *tree);
0217 XML_DEPRECATED
0218 XMLPUBFUN xmlAttributeTable *
0219         xmlCopyAttributeTable  (xmlAttributeTable *table);
0220 XML_DEPRECATED
0221 XMLPUBFUN void
0222         xmlFreeAttributeTable  (xmlAttributeTable *table);
0223 #ifdef LIBXML_OUTPUT_ENABLED
0224 XML_DEPRECATED
0225 XMLPUBFUN void
0226         xmlDumpAttributeTable  (xmlBuffer *buf,
0227                     xmlAttributeTable *table);
0228 XML_DEPRECATED
0229 XMLPUBFUN void
0230         xmlDumpAttributeDecl   (xmlBuffer *buf,
0231                     xmlAttribute *attr);
0232 #endif /* LIBXML_OUTPUT_ENABLED */
0233 
0234 /* IDs */
0235 XMLPUBFUN int
0236         xmlAddIDSafe           (xmlAttr *attr,
0237                     const xmlChar *value);
0238 XMLPUBFUN xmlID *
0239         xmlAddID           (xmlValidCtxt *ctxt,
0240                     xmlDoc *doc,
0241                     const xmlChar *value,
0242                     xmlAttr *attr);
0243 XMLPUBFUN void
0244         xmlFreeIDTable         (xmlIDTable *table);
0245 XMLPUBFUN xmlAttr *
0246         xmlGetID           (xmlDoc *doc,
0247                     const xmlChar *ID);
0248 XMLPUBFUN int
0249         xmlIsID            (xmlDoc *doc,
0250                     xmlNode *elem,
0251                     xmlAttr *attr);
0252 XMLPUBFUN int
0253         xmlRemoveID        (xmlDoc *doc,
0254                     xmlAttr *attr);
0255 
0256 /* IDREFs */
0257 XML_DEPRECATED
0258 XMLPUBFUN xmlRef *
0259         xmlAddRef          (xmlValidCtxt *ctxt,
0260                     xmlDoc *doc,
0261                     const xmlChar *value,
0262                     xmlAttr *attr);
0263 XML_DEPRECATED
0264 XMLPUBFUN void
0265         xmlFreeRefTable        (xmlRefTable *table);
0266 XML_DEPRECATED
0267 XMLPUBFUN int
0268         xmlIsRef           (xmlDoc *doc,
0269                     xmlNode *elem,
0270                     xmlAttr *attr);
0271 XML_DEPRECATED
0272 XMLPUBFUN int
0273         xmlRemoveRef           (xmlDoc *doc,
0274                     xmlAttr *attr);
0275 XML_DEPRECATED
0276 XMLPUBFUN xmlList *
0277         xmlGetRefs         (xmlDoc *doc,
0278                     const xmlChar *ID);
0279 
0280 /**
0281  * The public function calls related to validity checking.
0282  */
0283 #ifdef LIBXML_VALID_ENABLED
0284 /* Allocate/Release Validation Contexts */
0285 XMLPUBFUN xmlValidCtxt *
0286         xmlNewValidCtxt(void);
0287 XMLPUBFUN void
0288         xmlFreeValidCtxt(xmlValidCtxt *);
0289 
0290 XML_DEPRECATED
0291 XMLPUBFUN int
0292         xmlValidateRoot     (xmlValidCtxt *ctxt,
0293                      xmlDoc *doc);
0294 XML_DEPRECATED
0295 XMLPUBFUN int
0296         xmlValidateElementDecl  (xmlValidCtxt *ctxt,
0297                      xmlDoc *doc,
0298                                  xmlElement *elem);
0299 XML_DEPRECATED
0300 XMLPUBFUN xmlChar *
0301         xmlValidNormalizeAttributeValue(xmlDoc *doc,
0302                      xmlNode *elem,
0303                      const xmlChar *name,
0304                      const xmlChar *value);
0305 XML_DEPRECATED
0306 XMLPUBFUN xmlChar *
0307         xmlValidCtxtNormalizeAttributeValue(xmlValidCtxt *ctxt,
0308                      xmlDoc *doc,
0309                      xmlNode *elem,
0310                      const xmlChar *name,
0311                      const xmlChar *value);
0312 XML_DEPRECATED
0313 XMLPUBFUN int
0314         xmlValidateAttributeDecl(xmlValidCtxt *ctxt,
0315                      xmlDoc *doc,
0316                                  xmlAttribute *attr);
0317 XML_DEPRECATED
0318 XMLPUBFUN int
0319         xmlValidateAttributeValue(xmlAttributeType type,
0320                      const xmlChar *value);
0321 XML_DEPRECATED
0322 XMLPUBFUN int
0323         xmlValidateNotationDecl (xmlValidCtxt *ctxt,
0324                      xmlDoc *doc,
0325                                  xmlNotation *nota);
0326 XMLPUBFUN int
0327         xmlValidateDtd      (xmlValidCtxt *ctxt,
0328                      xmlDoc *doc,
0329                      xmlDtd *dtd);
0330 XML_DEPRECATED
0331 XMLPUBFUN int
0332         xmlValidateDtdFinal (xmlValidCtxt *ctxt,
0333                      xmlDoc *doc);
0334 XMLPUBFUN int
0335         xmlValidateDocument (xmlValidCtxt *ctxt,
0336                      xmlDoc *doc);
0337 XMLPUBFUN int
0338         xmlValidateElement  (xmlValidCtxt *ctxt,
0339                      xmlDoc *doc,
0340                      xmlNode *elem);
0341 XML_DEPRECATED
0342 XMLPUBFUN int
0343         xmlValidateOneElement   (xmlValidCtxt *ctxt,
0344                      xmlDoc *doc,
0345                                  xmlNode *elem);
0346 XML_DEPRECATED
0347 XMLPUBFUN int
0348         xmlValidateOneAttribute (xmlValidCtxt *ctxt,
0349                      xmlDoc *doc,
0350                      xmlNode    *elem,
0351                      xmlAttr *attr,
0352                      const xmlChar *value);
0353 XML_DEPRECATED
0354 XMLPUBFUN int
0355         xmlValidateOneNamespace (xmlValidCtxt *ctxt,
0356                      xmlDoc *doc,
0357                      xmlNode *elem,
0358                      const xmlChar *prefix,
0359                      xmlNs *ns,
0360                      const xmlChar *value);
0361 XML_DEPRECATED
0362 XMLPUBFUN int
0363         xmlValidateDocumentFinal(xmlValidCtxt *ctxt,
0364                      xmlDoc *doc);
0365 XML_DEPRECATED
0366 XMLPUBFUN int
0367         xmlValidateNotationUse  (xmlValidCtxt *ctxt,
0368                      xmlDoc *doc,
0369                      const xmlChar *notationName);
0370 #endif /* LIBXML_VALID_ENABLED */
0371 
0372 XML_DEPRECATED
0373 XMLPUBFUN int
0374         xmlIsMixedElement   (xmlDoc *doc,
0375                      const xmlChar *name);
0376 XMLPUBFUN xmlAttribute *
0377         xmlGetDtdAttrDesc   (xmlDtd *dtd,
0378                      const xmlChar *elem,
0379                      const xmlChar *name);
0380 XMLPUBFUN xmlAttribute *
0381         xmlGetDtdQAttrDesc  (xmlDtd *dtd,
0382                      const xmlChar *elem,
0383                      const xmlChar *name,
0384                      const xmlChar *prefix);
0385 XMLPUBFUN xmlNotation *
0386         xmlGetDtdNotationDesc   (xmlDtd *dtd,
0387                      const xmlChar *name);
0388 XMLPUBFUN xmlElement *
0389         xmlGetDtdQElementDesc   (xmlDtd *dtd,
0390                      const xmlChar *name,
0391                      const xmlChar *prefix);
0392 XMLPUBFUN xmlElement *
0393         xmlGetDtdElementDesc    (xmlDtd *dtd,
0394                      const xmlChar *name);
0395 
0396 #ifdef LIBXML_VALID_ENABLED
0397 
0398 XMLPUBFUN int
0399         xmlValidGetPotentialChildren(xmlElementContent *ctree,
0400                      const xmlChar **names,
0401                      int *len,
0402                      int max);
0403 
0404 /* only needed for `xmllint --insert` */
0405 XMLPUBFUN int
0406         xmlValidGetValidElements(xmlNode *prev,
0407                      xmlNode *next,
0408                      const xmlChar **names,
0409                      int max);
0410 XMLPUBFUN int
0411         xmlValidateNameValue    (const xmlChar *value);
0412 XMLPUBFUN int
0413         xmlValidateNamesValue   (const xmlChar *value);
0414 XMLPUBFUN int
0415         xmlValidateNmtokenValue (const xmlChar *value);
0416 XMLPUBFUN int
0417         xmlValidateNmtokensValue(const xmlChar *value);
0418 
0419 #ifdef LIBXML_REGEXP_ENABLED
0420 /*
0421  * Validation based on the regexp support
0422  */
0423 XML_DEPRECATED
0424 XMLPUBFUN int
0425         xmlValidBuildContentModel(xmlValidCtxt *ctxt,
0426                      xmlElement *elem);
0427 
0428 XML_DEPRECATED
0429 XMLPUBFUN int
0430         xmlValidatePushElement  (xmlValidCtxt *ctxt,
0431                      xmlDoc *doc,
0432                      xmlNode *elem,
0433                      const xmlChar *qname);
0434 XML_DEPRECATED
0435 XMLPUBFUN int
0436         xmlValidatePushCData    (xmlValidCtxt *ctxt,
0437                      const xmlChar *data,
0438                      int len);
0439 XML_DEPRECATED
0440 XMLPUBFUN int
0441         xmlValidatePopElement   (xmlValidCtxt *ctxt,
0442                      xmlDoc *doc,
0443                      xmlNode *elem,
0444                      const xmlChar *qname);
0445 #endif /* LIBXML_REGEXP_ENABLED */
0446 
0447 #endif /* LIBXML_VALID_ENABLED */
0448 
0449 #ifdef __cplusplus
0450 }
0451 #endif
0452 #endif /* __XML_VALID_H__ */