Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1 | /* |
| 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__ |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 12 | |
Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 13 | #include <libxml/tree.h> |
Daniel Veillard | 10cb900 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 14 | |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 19 | /** |
| 20 | * an xmlValidCtxt is used for error reporting when validating |
| 21 | */ |
| 22 | |
| 23 | typedef void (*xmlValidityErrorFunc) (void *ctx, const char *msg, ...); |
| 24 | typedef void (*xmlValidityWarningFunc) (void *ctx, const char *msg, ...); |
| 25 | |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 26 | typedef struct _xmlValidCtxt xmlValidCtxt; |
| 27 | typedef xmlValidCtxt *xmlValidCtxtPtr; |
| 28 | struct _xmlValidCtxt { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 29 | void *userData; /* user specific data block */ |
| 30 | xmlValidityErrorFunc error; /* the callback in case of errors */ |
| 31 | xmlValidityWarningFunc warning; /* the callback in case of warning */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 32 | |
| 33 | /* Node analysis stack used when validating within entities */ |
| 34 | xmlNodePtr node; /* Current parsed Node */ |
| 35 | int nodeNr; /* Depth of the parsing stack */ |
| 36 | int nodeMax; /* Max depth of the parsing stack */ |
| 37 | xmlNodePtr *nodeTab; /* array of nodes */ |
| 38 | |
| 39 | int finishDtd; /* finished validating the Dtd ? */ |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 40 | }; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 41 | |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 42 | /* |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 43 | * ALl notation declarations are stored in a table |
| 44 | * there is one table per DTD |
| 45 | */ |
| 46 | |
| 47 | #define XML_MIN_NOTATION_TABLE 32 |
| 48 | |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 49 | typedef struct _xmlNotationTable xmlNotationTable; |
| 50 | typedef xmlNotationTable *xmlNotationTablePtr; |
| 51 | struct _xmlNotationTable { |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 52 | int nb_notations; /* number of notations stored */ |
| 53 | int max_notations; /* maximum number of notations */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 54 | xmlNotationPtr *table; /* the table of attributes */ |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 55 | }; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 56 | |
| 57 | /* |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 58 | * ALl element declarations are stored in a table |
| 59 | * there is one table per DTD |
| 60 | */ |
| 61 | |
| 62 | #define XML_MIN_ELEMENT_TABLE 32 |
| 63 | |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 64 | typedef struct _xmlElementTable xmlElementTable; |
| 65 | typedef xmlElementTable *xmlElementTablePtr; |
| 66 | struct _xmlElementTable { |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 67 | int nb_elements; /* number of elements stored */ |
| 68 | int max_elements; /* maximum number of elements */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 69 | xmlElementPtr *table; /* the table of elements */ |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 70 | }; |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 71 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 72 | /* |
| 73 | * ALl attribute declarations are stored in a table |
| 74 | * there is one table per DTD |
| 75 | */ |
| 76 | |
| 77 | #define XML_MIN_ATTRIBUTE_TABLE 32 |
| 78 | |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 79 | typedef struct _xmlAttributeTable xmlAttributeTable; |
| 80 | typedef xmlAttributeTable *xmlAttributeTablePtr; |
| 81 | struct _xmlAttributeTable { |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 82 | int nb_attributes; /* number of attributes stored */ |
| 83 | int max_attributes; /* maximum number of attributes */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 84 | xmlAttributePtr *table; /* the table of attributes */ |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 85 | }; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 86 | |
Daniel Veillard | 991e63d | 1999-08-15 23:32:28 +0000 | [diff] [blame] | 87 | /* |
| 88 | * ALl IDs attributes are stored in a table |
| 89 | * there is one table per document |
| 90 | */ |
| 91 | |
| 92 | #define XML_MIN_ID_TABLE 32 |
| 93 | |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 94 | typedef struct _xmlIDTable xmlIDTable; |
| 95 | typedef xmlIDTable *xmlIDTablePtr; |
| 96 | struct _xmlIDTable { |
Daniel Veillard | 991e63d | 1999-08-15 23:32:28 +0000 | [diff] [blame] | 97 | int nb_ids; /* number of ids stored */ |
| 98 | int max_ids; /* maximum number of ids */ |
| 99 | xmlIDPtr *table; /* the table of ids */ |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 100 | }; |
Daniel Veillard | 991e63d | 1999-08-15 23:32:28 +0000 | [diff] [blame] | 101 | |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 102 | /* |
| 103 | * ALl Refs attributes are stored in a table |
| 104 | * there is one table per document |
| 105 | */ |
| 106 | |
| 107 | #define XML_MIN_REF_TABLE 32 |
| 108 | |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 109 | typedef struct _xmlRefTable xmlRefTable; |
| 110 | typedef xmlRefTable *xmlRefTablePtr; |
| 111 | struct _xmlRefTable { |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 112 | int nb_refs; /* number of refs stored */ |
| 113 | int max_refs; /* maximum number of refs */ |
| 114 | xmlRefPtr *table; /* the table of refs */ |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 115 | }; |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 116 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 117 | /* Notation */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 118 | xmlNotationPtr xmlAddNotationDecl (xmlValidCtxtPtr ctxt, |
| 119 | xmlDtdPtr dtd, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 120 | const xmlChar *name, |
| 121 | const xmlChar *PublicID, |
| 122 | const xmlChar *SystemID); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 123 | xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 124 | void xmlFreeNotationTable(xmlNotationTablePtr table); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 125 | void xmlDumpNotationDecl (xmlBufferPtr buf, |
| 126 | xmlNotationPtr nota); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 127 | void xmlDumpNotationTable(xmlBufferPtr buf, |
| 128 | xmlNotationTablePtr table); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 129 | |
| 130 | /* Element Content */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 131 | xmlElementContentPtr xmlNewElementContent (xmlChar *name, |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 132 | xmlElementContentType type); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 133 | xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 134 | void xmlFreeElementContent(xmlElementContentPtr cur); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 135 | void xmlSprintfElementContent(char *buf, |
| 136 | xmlElementContentPtr content, |
| 137 | int glob); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 138 | |
| 139 | /* Element */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 140 | xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt, |
| 141 | xmlDtdPtr dtd, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 142 | const xmlChar *name, |
Daniel Veillard | 51e3b15 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 143 | xmlElementTypeVal type, |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 144 | xmlElementContentPtr content); |
| 145 | xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table); |
| 146 | void xmlFreeElementTable (xmlElementTablePtr table); |
| 147 | void xmlDumpElementTable (xmlBufferPtr buf, |
| 148 | xmlElementTablePtr table); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 149 | void xmlDumpElementDecl (xmlBufferPtr buf, |
| 150 | xmlElementPtr elem); |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 151 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 152 | /* Enumeration */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 153 | xmlEnumerationPtr xmlCreateEnumeration (xmlChar *name); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 154 | void xmlFreeEnumeration (xmlEnumerationPtr cur); |
| 155 | xmlEnumerationPtr xmlCopyEnumeration (xmlEnumerationPtr cur); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 156 | |
| 157 | /* Attribute */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 158 | xmlAttributePtr xmlAddAttributeDecl (xmlValidCtxtPtr ctxt, |
| 159 | xmlDtdPtr dtd, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 160 | const xmlChar *elem, |
| 161 | const xmlChar *name, |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 162 | const xmlChar *ns, |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 163 | xmlAttributeType type, |
| 164 | xmlAttributeDefault def, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 165 | const xmlChar *defaultValue, |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 166 | xmlEnumerationPtr tree); |
| 167 | xmlAttributeTablePtr xmlCopyAttributeTable (xmlAttributeTablePtr table); |
| 168 | void xmlFreeAttributeTable (xmlAttributeTablePtr table); |
| 169 | void xmlDumpAttributeTable (xmlBufferPtr buf, |
| 170 | xmlAttributeTablePtr table); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 171 | void xmlDumpAttributeDecl (xmlBufferPtr buf, |
| 172 | xmlAttributePtr attr); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 173 | |
Daniel Veillard | 991e63d | 1999-08-15 23:32:28 +0000 | [diff] [blame] | 174 | /* IDs */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 175 | xmlIDPtr xmlAddID (xmlValidCtxtPtr ctxt, |
| 176 | xmlDocPtr doc, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 177 | const xmlChar *value, |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 178 | xmlAttrPtr attr); |
| 179 | xmlIDTablePtr xmlCopyIDTable (xmlIDTablePtr table); |
| 180 | void xmlFreeIDTable (xmlIDTablePtr table); |
| 181 | xmlAttrPtr xmlGetID (xmlDocPtr doc, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 182 | const xmlChar *ID); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 183 | int xmlIsID (xmlDocPtr doc, |
| 184 | xmlNodePtr elem, |
| 185 | xmlAttrPtr attr); |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 186 | int xmlRemoveID (xmlDocPtr doc, xmlAttrPtr attr); |
Daniel Veillard | 991e63d | 1999-08-15 23:32:28 +0000 | [diff] [blame] | 187 | |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 188 | /* IDREFs */ |
| 189 | xmlRefPtr xmlAddRef (xmlValidCtxtPtr ctxt, |
| 190 | xmlDocPtr doc, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 191 | const xmlChar *value, |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 192 | xmlAttrPtr attr); |
| 193 | xmlRefTablePtr xmlCopyRefTable (xmlRefTablePtr table); |
| 194 | void xmlFreeRefTable (xmlRefTablePtr table); |
| 195 | int xmlIsRef (xmlDocPtr doc, |
| 196 | xmlNodePtr elem, |
| 197 | xmlAttrPtr attr); |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 198 | int xmlRemoveRef (xmlDocPtr doc, xmlAttrPtr attr); |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 199 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 200 | /** |
| 201 | * The public function calls related to validity checking |
| 202 | */ |
| 203 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 204 | int xmlValidateRoot (xmlValidCtxtPtr ctxt, |
| 205 | xmlDocPtr doc); |
| 206 | int xmlValidateElementDecl (xmlValidCtxtPtr ctxt, |
| 207 | xmlDocPtr doc, |
| 208 | xmlElementPtr elem); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 209 | xmlChar * xmlValidNormalizeAttributeValue(xmlDocPtr doc, |
| 210 | xmlNodePtr elem, |
| 211 | const xmlChar *name, |
| 212 | const xmlChar *value); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 213 | int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, |
| 214 | xmlDocPtr doc, |
| 215 | xmlAttributePtr attr); |
| 216 | int xmlValidateAttributeValue(xmlAttributeType type, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 217 | const xmlChar *value); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 218 | int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt, |
| 219 | xmlDocPtr doc, |
| 220 | xmlNotationPtr nota); |
| 221 | int xmlValidateDtd (xmlValidCtxtPtr ctxt, |
| 222 | xmlDocPtr doc, |
| 223 | xmlDtdPtr dtd); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 224 | int xmlValidateDtdFinal (xmlValidCtxtPtr ctxt, |
| 225 | xmlDocPtr doc); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 226 | int xmlValidateDocument (xmlValidCtxtPtr ctxt, |
| 227 | xmlDocPtr doc); |
| 228 | int xmlValidateElement (xmlValidCtxtPtr ctxt, |
| 229 | xmlDocPtr doc, |
| 230 | xmlNodePtr elem); |
| 231 | int xmlValidateOneElement (xmlValidCtxtPtr ctxt, |
| 232 | xmlDocPtr doc, |
| 233 | xmlNodePtr elem); |
| 234 | int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt, |
| 235 | xmlDocPtr doc, |
| 236 | xmlNodePtr elem, |
| 237 | xmlAttrPtr attr, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 238 | const xmlChar *value); |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 239 | int xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, |
| 240 | xmlDocPtr doc); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 241 | int xmlValidateNotationUse (xmlValidCtxtPtr ctxt, |
| 242 | xmlDocPtr doc, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 243 | const xmlChar *notationName); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 244 | int xmlIsMixedElement (xmlDocPtr doc, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 245 | const xmlChar *name); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 246 | xmlAttributePtr xmlGetDtdAttrDesc (xmlDtdPtr dtd, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 247 | const xmlChar *elem, |
| 248 | const xmlChar *name); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 249 | xmlNotationPtr xmlGetDtdNotationDesc (xmlDtdPtr dtd, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 250 | const xmlChar *name); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 251 | xmlElementPtr xmlGetDtdElementDesc (xmlDtdPtr dtd, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 252 | const xmlChar *name); |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 253 | |
Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 254 | int xmlValidGetValidElements(xmlNode *prev, |
| 255 | xmlNode *next, |
| 256 | const xmlChar **list, |
| 257 | int max); |
| 258 | int xmlValidGetPotentialChildren(xmlElementContent *ctree, |
| 259 | const xmlChar **list, |
| 260 | int *len, |
| 261 | int max); |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 262 | #ifdef __cplusplus |
| 263 | } |
| 264 | #endif |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 265 | #endif /* __XML_VALID_H__ */ |