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