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