1 /* 2 * Summary: incomplete XML Schemas structure implementation 3 * Description: interface to the XML Schemas handling and schema validity 4 * checking, it is incomplete right now. 5 * 6 * Copy: See Copyright for the status of this software. 7 * 8 * Author: Daniel Veillard 9 */ 10 11 12 #ifndef __XML_SCHEMA_H__ 13 #define __XML_SCHEMA_H__ 14 15 #include <libxml/xmlversion.h> 16 17 #ifdef LIBXML_SCHEMAS_ENABLED 18 19 #include <stdio.h> 20 #include <libxml/encoding.h> 21 #include <libxml/tree.h> 22 #include <libxml/xmlerror.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /** 29 * This error codes are obsolete; not used any more. 30 */ 31 typedef enum { 32 XML_SCHEMAS_ERR_OK = 0, 33 XML_SCHEMAS_ERR_NOROOT = 1, 34 XML_SCHEMAS_ERR_UNDECLAREDELEM, 35 XML_SCHEMAS_ERR_NOTTOPLEVEL, 36 XML_SCHEMAS_ERR_MISSING, 37 XML_SCHEMAS_ERR_WRONGELEM, 38 XML_SCHEMAS_ERR_NOTYPE, 39 XML_SCHEMAS_ERR_NOROLLBACK, 40 XML_SCHEMAS_ERR_ISABSTRACT, 41 XML_SCHEMAS_ERR_NOTEMPTY, 42 XML_SCHEMAS_ERR_ELEMCONT, 43 XML_SCHEMAS_ERR_HAVEDEFAULT, 44 XML_SCHEMAS_ERR_NOTNILLABLE, 45 XML_SCHEMAS_ERR_EXTRACONTENT, 46 XML_SCHEMAS_ERR_INVALIDATTR, 47 XML_SCHEMAS_ERR_INVALIDELEM, 48 XML_SCHEMAS_ERR_NOTDETERMINIST, 49 XML_SCHEMAS_ERR_CONSTRUCT, 50 XML_SCHEMAS_ERR_INTERNAL, 51 XML_SCHEMAS_ERR_NOTSIMPLE, 52 XML_SCHEMAS_ERR_ATTRUNKNOWN, 53 XML_SCHEMAS_ERR_ATTRINVALID, 54 XML_SCHEMAS_ERR_VALUE, 55 XML_SCHEMAS_ERR_FACET, 56 XML_SCHEMAS_ERR_, 57 XML_SCHEMAS_ERR_XXX 58 } xmlSchemaValidError; 59 60 /* 61 * ATTENTION: Change xmlSchemaSetValidOptions's check 62 * for invalid values, if adding to the validation 63 * options below. 64 */ 65 /** 66 * xmlSchemaValidOption: 67 * 68 * This is the set of XML Schema validation options. 69 */ 70 typedef enum { 71 XML_SCHEMA_VAL_VC_I_CREATE = 1<<0 72 /* Default/fixed: create an attribute node 73 * or an element's text node on the instance. 74 */ 75 } xmlSchemaValidOption; 76 77 /* 78 XML_SCHEMA_VAL_XSI_ASSEMBLE = 1<<1, 79 * assemble schemata using 80 * xsi:schemaLocation and 81 * xsi:noNamespaceSchemaLocation 82 */ 83 84 /** 85 * The schemas related types are kept internal 86 */ 87 typedef struct _xmlSchema xmlSchema; 88 typedef xmlSchema *xmlSchemaPtr; 89 90 /** 91 * xmlSchemaValidityErrorFunc: 92 * @ctx: the validation context 93 * @msg: the message 94 * @...: extra arguments 95 * 96 * Signature of an error callback from an XSD validation 97 */ 98 typedef void (*xmlSchemaValidityErrorFunc) 99 (void *ctx, const char *msg, ...) LIBXML_ATTR_FORMAT(2,3); 100 101 /** 102 * xmlSchemaValidityWarningFunc: 103 * @ctx: the validation context 104 * @msg: the message 105 * @...: extra arguments 106 * 107 * Signature of a warning callback from an XSD validation 108 */ 109 typedef void (*xmlSchemaValidityWarningFunc) 110 (void *ctx, const char *msg, ...) LIBXML_ATTR_FORMAT(2,3); 111 112 /** 113 * A schemas validation context 114 */ 115 typedef struct _xmlSchemaParserCtxt xmlSchemaParserCtxt; 116 typedef xmlSchemaParserCtxt *xmlSchemaParserCtxtPtr; 117 118 typedef struct _xmlSchemaValidCtxt xmlSchemaValidCtxt; 119 typedef xmlSchemaValidCtxt *xmlSchemaValidCtxtPtr; 120 121 /** 122 * xmlSchemaValidityLocatorFunc: 123 * @ctx: user provided context 124 * @file: returned file information 125 * @line: returned line information 126 * 127 * A schemas validation locator, a callback called by the validator. 128 * This is used when file or node information are not available 129 * to find out what file and line number are affected 130 * 131 * Returns: 0 in case of success and -1 in case of error 132 */ 133 134 typedef int (*xmlSchemaValidityLocatorFunc) (void *ctx, 135 const char **file, unsigned long *line); 136 137 /* 138 * Interfaces for parsing. 139 */ 140 XMLPUBFUN xmlSchemaParserCtxtPtr 141 xmlSchemaNewParserCtxt (const char *URL); 142 XMLPUBFUN xmlSchemaParserCtxtPtr 143 xmlSchemaNewMemParserCtxt (const char *buffer, 144 int size); 145 XMLPUBFUN xmlSchemaParserCtxtPtr 146 xmlSchemaNewDocParserCtxt (xmlDocPtr doc); 147 XMLPUBFUN void 148 xmlSchemaFreeParserCtxt (xmlSchemaParserCtxtPtr ctxt); 149 XMLPUBFUN void 150 xmlSchemaSetParserErrors (xmlSchemaParserCtxtPtr ctxt, 151 xmlSchemaValidityErrorFunc err, 152 xmlSchemaValidityWarningFunc warn, 153 void *ctx); 154 XMLPUBFUN void 155 xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxtPtr ctxt, 156 xmlStructuredErrorFunc serror, 157 void *ctx); 158 XMLPUBFUN int 159 xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt, 160 xmlSchemaValidityErrorFunc * err, 161 xmlSchemaValidityWarningFunc * warn, 162 void **ctx); 163 XMLPUBFUN int 164 xmlSchemaIsValid (xmlSchemaValidCtxtPtr ctxt); 165 166 XMLPUBFUN xmlSchemaPtr 167 xmlSchemaParse (xmlSchemaParserCtxtPtr ctxt); 168 XMLPUBFUN void 169 xmlSchemaFree (xmlSchemaPtr schema); 170 #ifdef LIBXML_OUTPUT_ENABLED 171 XMLPUBFUN void 172 xmlSchemaDump (FILE *output, 173 xmlSchemaPtr schema); 174 #endif /* LIBXML_OUTPUT_ENABLED */ 175 /* 176 * Interfaces for validating 177 */ 178 XMLPUBFUN void 179 xmlSchemaSetValidErrors (xmlSchemaValidCtxtPtr ctxt, 180 xmlSchemaValidityErrorFunc err, 181 xmlSchemaValidityWarningFunc warn, 182 void *ctx); 183 XMLPUBFUN void 184 xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxtPtr ctxt, 185 xmlStructuredErrorFunc serror, 186 void *ctx); 187 XMLPUBFUN int 188 xmlSchemaGetValidErrors (xmlSchemaValidCtxtPtr ctxt, 189 xmlSchemaValidityErrorFunc *err, 190 xmlSchemaValidityWarningFunc *warn, 191 void **ctx); 192 XMLPUBFUN int 193 xmlSchemaSetValidOptions (xmlSchemaValidCtxtPtr ctxt, 194 int options); 195 XMLPUBFUN void 196 xmlSchemaValidateSetFilename(xmlSchemaValidCtxtPtr vctxt, 197 const char *filename); 198 XMLPUBFUN int 199 xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt); 200 201 XMLPUBFUN xmlSchemaValidCtxtPtr 202 xmlSchemaNewValidCtxt (xmlSchemaPtr schema); 203 XMLPUBFUN void 204 xmlSchemaFreeValidCtxt (xmlSchemaValidCtxtPtr ctxt); 205 XMLPUBFUN int 206 xmlSchemaValidateDoc (xmlSchemaValidCtxtPtr ctxt, 207 xmlDocPtr instance); 208 XMLPUBFUN int 209 xmlSchemaValidateOneElement (xmlSchemaValidCtxtPtr ctxt, 210 xmlNodePtr elem); 211 XMLPUBFUN int 212 xmlSchemaValidateStream (xmlSchemaValidCtxtPtr ctxt, 213 xmlParserInputBufferPtr input, 214 xmlCharEncoding enc, 215 xmlSAXHandlerPtr sax, 216 void *user_data); 217 XMLPUBFUN int 218 xmlSchemaValidateFile (xmlSchemaValidCtxtPtr ctxt, 219 const char * filename, 220 int options); 221 222 XMLPUBFUN xmlParserCtxtPtr 223 xmlSchemaValidCtxtGetParserCtxt(xmlSchemaValidCtxtPtr ctxt); 224 225 /* 226 * Interface to insert Schemas SAX validation in a SAX stream 227 */ 228 typedef struct _xmlSchemaSAXPlug xmlSchemaSAXPlugStruct; 229 typedef xmlSchemaSAXPlugStruct *xmlSchemaSAXPlugPtr; 230 231 XMLPUBFUN xmlSchemaSAXPlugPtr 232 xmlSchemaSAXPlug (xmlSchemaValidCtxtPtr ctxt, 233 xmlSAXHandlerPtr *sax, 234 void **user_data); 235 XMLPUBFUN int 236 xmlSchemaSAXUnplug (xmlSchemaSAXPlugPtr plug); 237 238 239 XMLPUBFUN void 240 xmlSchemaValidateSetLocator (xmlSchemaValidCtxtPtr vctxt, 241 xmlSchemaValidityLocatorFunc f, 242 void *ctxt); 243 244 #ifdef __cplusplus 245 } 246 #endif 247 248 #endif /* LIBXML_SCHEMAS_ENABLED */ 249 #endif /* __XML_SCHEMA_H__ */ 250