You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
5.9 KiB

4 years ago
  1. /*
  2. * Summary: implementation of the Relax-NG validation
  3. * Description: implementation of the Relax-NG validation
  4. *
  5. * Copy: See Copyright for the status of this software.
  6. *
  7. * Author: Daniel Veillard
  8. */
  9. #ifndef __XML_RELAX_NG__
  10. #define __XML_RELAX_NG__
  11. #include <libxml/xmlversion.h>
  12. #include <libxml/hash.h>
  13. #include <libxml/xmlstring.h>
  14. #ifdef LIBXML_SCHEMAS_ENABLED
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. typedef struct _xmlRelaxNG xmlRelaxNG;
  19. typedef xmlRelaxNG *xmlRelaxNGPtr;
  20. /**
  21. * xmlRelaxNGValidityErrorFunc:
  22. * @ctx: the validation context
  23. * @msg: the message
  24. * @...: extra arguments
  25. *
  26. * Signature of an error callback from a Relax-NG validation
  27. */
  28. typedef void (XMLCDECL *xmlRelaxNGValidityErrorFunc) (void *ctx,
  29. const char *msg,
  30. ...) LIBXML_ATTR_FORMAT(2,3);
  31. /**
  32. * xmlRelaxNGValidityWarningFunc:
  33. * @ctx: the validation context
  34. * @msg: the message
  35. * @...: extra arguments
  36. *
  37. * Signature of a warning callback from a Relax-NG validation
  38. */
  39. typedef void (XMLCDECL *xmlRelaxNGValidityWarningFunc) (void *ctx,
  40. const char *msg,
  41. ...) LIBXML_ATTR_FORMAT(2,3);
  42. /**
  43. * A schemas validation context
  44. */
  45. typedef struct _xmlRelaxNGParserCtxt xmlRelaxNGParserCtxt;
  46. typedef xmlRelaxNGParserCtxt *xmlRelaxNGParserCtxtPtr;
  47. typedef struct _xmlRelaxNGValidCtxt xmlRelaxNGValidCtxt;
  48. typedef xmlRelaxNGValidCtxt *xmlRelaxNGValidCtxtPtr;
  49. /*
  50. * xmlRelaxNGValidErr:
  51. *
  52. * List of possible Relax NG validation errors
  53. */
  54. typedef enum {
  55. XML_RELAXNG_OK = 0,
  56. XML_RELAXNG_ERR_MEMORY,
  57. XML_RELAXNG_ERR_TYPE,
  58. XML_RELAXNG_ERR_TYPEVAL,
  59. XML_RELAXNG_ERR_DUPID,
  60. XML_RELAXNG_ERR_TYPECMP,
  61. XML_RELAXNG_ERR_NOSTATE,
  62. XML_RELAXNG_ERR_NODEFINE,
  63. XML_RELAXNG_ERR_LISTEXTRA,
  64. XML_RELAXNG_ERR_LISTEMPTY,
  65. XML_RELAXNG_ERR_INTERNODATA,
  66. XML_RELAXNG_ERR_INTERSEQ,
  67. XML_RELAXNG_ERR_INTEREXTRA,
  68. XML_RELAXNG_ERR_ELEMNAME,
  69. XML_RELAXNG_ERR_ATTRNAME,
  70. XML_RELAXNG_ERR_ELEMNONS,
  71. XML_RELAXNG_ERR_ATTRNONS,
  72. XML_RELAXNG_ERR_ELEMWRONGNS,
  73. XML_RELAXNG_ERR_ATTRWRONGNS,
  74. XML_RELAXNG_ERR_ELEMEXTRANS,
  75. XML_RELAXNG_ERR_ATTREXTRANS,
  76. XML_RELAXNG_ERR_ELEMNOTEMPTY,
  77. XML_RELAXNG_ERR_NOELEM,
  78. XML_RELAXNG_ERR_NOTELEM,
  79. XML_RELAXNG_ERR_ATTRVALID,
  80. XML_RELAXNG_ERR_CONTENTVALID,
  81. XML_RELAXNG_ERR_EXTRACONTENT,
  82. XML_RELAXNG_ERR_INVALIDATTR,
  83. XML_RELAXNG_ERR_DATAELEM,
  84. XML_RELAXNG_ERR_VALELEM,
  85. XML_RELAXNG_ERR_LISTELEM,
  86. XML_RELAXNG_ERR_DATATYPE,
  87. XML_RELAXNG_ERR_VALUE,
  88. XML_RELAXNG_ERR_LIST,
  89. XML_RELAXNG_ERR_NOGRAMMAR,
  90. XML_RELAXNG_ERR_EXTRADATA,
  91. XML_RELAXNG_ERR_LACKDATA,
  92. XML_RELAXNG_ERR_INTERNAL,
  93. XML_RELAXNG_ERR_ELEMWRONG,
  94. XML_RELAXNG_ERR_TEXTWRONG
  95. } xmlRelaxNGValidErr;
  96. /*
  97. * xmlRelaxNGParserFlags:
  98. *
  99. * List of possible Relax NG Parser flags
  100. */
  101. typedef enum {
  102. XML_RELAXNGP_NONE = 0,
  103. XML_RELAXNGP_FREE_DOC = 1,
  104. XML_RELAXNGP_CRNG = 2
  105. } xmlRelaxNGParserFlag;
  106. XMLPUBFUN int XMLCALL
  107. xmlRelaxNGInitTypes (void);
  108. XMLPUBFUN void XMLCALL
  109. xmlRelaxNGCleanupTypes (void);
  110. /*
  111. * Interfaces for parsing.
  112. */
  113. XMLPUBFUN xmlRelaxNGParserCtxtPtr XMLCALL
  114. xmlRelaxNGNewParserCtxt (const char *URL);
  115. XMLPUBFUN xmlRelaxNGParserCtxtPtr XMLCALL
  116. xmlRelaxNGNewMemParserCtxt (const char *buffer,
  117. int size);
  118. XMLPUBFUN xmlRelaxNGParserCtxtPtr XMLCALL
  119. xmlRelaxNGNewDocParserCtxt (xmlDocPtr doc);
  120. XMLPUBFUN int XMLCALL
  121. xmlRelaxParserSetFlag (xmlRelaxNGParserCtxtPtr ctxt,
  122. int flag);
  123. XMLPUBFUN void XMLCALL
  124. xmlRelaxNGFreeParserCtxt (xmlRelaxNGParserCtxtPtr ctxt);
  125. XMLPUBFUN void XMLCALL
  126. xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
  127. xmlRelaxNGValidityErrorFunc err,
  128. xmlRelaxNGValidityWarningFunc warn,
  129. void *ctx);
  130. XMLPUBFUN int XMLCALL
  131. xmlRelaxNGGetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
  132. xmlRelaxNGValidityErrorFunc *err,
  133. xmlRelaxNGValidityWarningFunc *warn,
  134. void **ctx);
  135. XMLPUBFUN void XMLCALL
  136. xmlRelaxNGSetParserStructuredErrors(
  137. xmlRelaxNGParserCtxtPtr ctxt,
  138. xmlStructuredErrorFunc serror,
  139. void *ctx);
  140. XMLPUBFUN xmlRelaxNGPtr XMLCALL
  141. xmlRelaxNGParse (xmlRelaxNGParserCtxtPtr ctxt);
  142. XMLPUBFUN void XMLCALL
  143. xmlRelaxNGFree (xmlRelaxNGPtr schema);
  144. #ifdef LIBXML_OUTPUT_ENABLED
  145. XMLPUBFUN void XMLCALL
  146. xmlRelaxNGDump (FILE *output,
  147. xmlRelaxNGPtr schema);
  148. XMLPUBFUN void XMLCALL
  149. xmlRelaxNGDumpTree (FILE * output,
  150. xmlRelaxNGPtr schema);
  151. #endif /* LIBXML_OUTPUT_ENABLED */
  152. /*
  153. * Interfaces for validating
  154. */
  155. XMLPUBFUN void XMLCALL
  156. xmlRelaxNGSetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
  157. xmlRelaxNGValidityErrorFunc err,
  158. xmlRelaxNGValidityWarningFunc warn,
  159. void *ctx);
  160. XMLPUBFUN int XMLCALL
  161. xmlRelaxNGGetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
  162. xmlRelaxNGValidityErrorFunc *err,
  163. xmlRelaxNGValidityWarningFunc *warn,
  164. void **ctx);
  165. XMLPUBFUN void XMLCALL
  166. xmlRelaxNGSetValidStructuredErrors(xmlRelaxNGValidCtxtPtr ctxt,
  167. xmlStructuredErrorFunc serror, void *ctx);
  168. XMLPUBFUN xmlRelaxNGValidCtxtPtr XMLCALL
  169. xmlRelaxNGNewValidCtxt (xmlRelaxNGPtr schema);
  170. XMLPUBFUN void XMLCALL
  171. xmlRelaxNGFreeValidCtxt (xmlRelaxNGValidCtxtPtr ctxt);
  172. XMLPUBFUN int XMLCALL
  173. xmlRelaxNGValidateDoc (xmlRelaxNGValidCtxtPtr ctxt,
  174. xmlDocPtr doc);
  175. /*
  176. * Interfaces for progressive validation when possible
  177. */
  178. XMLPUBFUN int XMLCALL
  179. xmlRelaxNGValidatePushElement (xmlRelaxNGValidCtxtPtr ctxt,
  180. xmlDocPtr doc,
  181. xmlNodePtr elem);
  182. XMLPUBFUN int XMLCALL
  183. xmlRelaxNGValidatePushCData (xmlRelaxNGValidCtxtPtr ctxt,
  184. const xmlChar *data,
  185. int len);
  186. XMLPUBFUN int XMLCALL
  187. xmlRelaxNGValidatePopElement (xmlRelaxNGValidCtxtPtr ctxt,
  188. xmlDocPtr doc,
  189. xmlNodePtr elem);
  190. XMLPUBFUN int XMLCALL
  191. xmlRelaxNGValidateFullElement (xmlRelaxNGValidCtxtPtr ctxt,
  192. xmlDocPtr doc,
  193. xmlNodePtr elem);
  194. #ifdef __cplusplus
  195. }
  196. #endif
  197. #endif /* LIBXML_SCHEMAS_ENABLED */
  198. #endif /* __XML_RELAX_NG__ */