xmlschemas.h 6.7 KB

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