valid.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*
  2. * Summary: The DTD validation
  3. * Description: API for the DTD handling and the validity checking
  4. *
  5. * Copy: See Copyright for the status of this software.
  6. *
  7. * Author: Daniel Veillard
  8. */
  9. #ifndef __XML_VALID_H__
  10. #define __XML_VALID_H__
  11. #include <libxml/xmlversion.h>
  12. #include <libxml/xmlerror.h>
  13. #include <libxml/tree.h>
  14. #include <libxml/list.h>
  15. #include <libxml/xmlautomata.h>
  16. #include <libxml/xmlregexp.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /*
  21. * Validation state added for non-determinist content model.
  22. */
  23. typedef struct _xmlValidState xmlValidState;
  24. typedef xmlValidState *xmlValidStatePtr;
  25. /**
  26. * xmlValidityErrorFunc:
  27. * @ctx: usually an xmlValidCtxtPtr to a validity error context,
  28. * but comes from ctxt->userData (which normally contains such
  29. * a pointer); ctxt->userData can be changed by the user.
  30. * @msg: the string to format *printf like vararg
  31. * @...: remaining arguments to the format
  32. *
  33. * Callback called when a validity error is found. This is a message
  34. * oriented function similar to an *printf function.
  35. */
  36. typedef void (*xmlValidityErrorFunc) (void *ctx,
  37. const char *msg,
  38. ...) LIBXML_ATTR_FORMAT(2,3);
  39. /**
  40. * xmlValidityWarningFunc:
  41. * @ctx: usually an xmlValidCtxtPtr to a validity error context,
  42. * but comes from ctxt->userData (which normally contains such
  43. * a pointer); ctxt->userData can be changed by the user.
  44. * @msg: the string to format *printf like vararg
  45. * @...: remaining arguments to the format
  46. *
  47. * Callback called when a validity warning is found. This is a message
  48. * oriented function similar to an *printf function.
  49. */
  50. typedef void (*xmlValidityWarningFunc) (void *ctx,
  51. const char *msg,
  52. ...) LIBXML_ATTR_FORMAT(2,3);
  53. /*
  54. * xmlValidCtxt:
  55. * An xmlValidCtxt is used for error reporting when validating.
  56. */
  57. typedef struct _xmlValidCtxt xmlValidCtxt;
  58. typedef xmlValidCtxt *xmlValidCtxtPtr;
  59. struct _xmlValidCtxt {
  60. void *userData; /* user specific data block */
  61. xmlValidityErrorFunc error; /* the callback in case of errors */
  62. xmlValidityWarningFunc warning; /* the callback in case of warning */
  63. /* Node analysis stack used when validating within entities */
  64. xmlNodePtr node; /* Current parsed Node */
  65. int nodeNr; /* Depth of the parsing stack */
  66. int nodeMax; /* Max depth of the parsing stack */
  67. xmlNodePtr *nodeTab; /* array of nodes */
  68. unsigned int flags; /* internal flags */
  69. xmlDocPtr doc; /* the document */
  70. int valid; /* temporary validity check result */
  71. /* state state used for non-determinist content validation */
  72. xmlValidState *vstate; /* current state */
  73. int vstateNr; /* Depth of the validation stack */
  74. int vstateMax; /* Max depth of the validation stack */
  75. xmlValidState *vstateTab; /* array of validation states */
  76. #ifdef LIBXML_REGEXP_ENABLED
  77. xmlAutomataPtr am; /* the automata */
  78. xmlAutomataStatePtr state; /* used to build the automata */
  79. #else
  80. void *am;
  81. void *state;
  82. #endif
  83. };
  84. /*
  85. * ALL notation declarations are stored in a table.
  86. * There is one table per DTD.
  87. */
  88. typedef struct _xmlHashTable xmlNotationTable;
  89. typedef xmlNotationTable *xmlNotationTablePtr;
  90. /*
  91. * ALL element declarations are stored in a table.
  92. * There is one table per DTD.
  93. */
  94. typedef struct _xmlHashTable xmlElementTable;
  95. typedef xmlElementTable *xmlElementTablePtr;
  96. /*
  97. * ALL attribute declarations are stored in a table.
  98. * There is one table per DTD.
  99. */
  100. typedef struct _xmlHashTable xmlAttributeTable;
  101. typedef xmlAttributeTable *xmlAttributeTablePtr;
  102. /*
  103. * ALL IDs attributes are stored in a table.
  104. * There is one table per document.
  105. */
  106. typedef struct _xmlHashTable xmlIDTable;
  107. typedef xmlIDTable *xmlIDTablePtr;
  108. /*
  109. * ALL Refs attributes are stored in a table.
  110. * There is one table per document.
  111. */
  112. typedef struct _xmlHashTable xmlRefTable;
  113. typedef xmlRefTable *xmlRefTablePtr;
  114. /* Notation */
  115. XMLPUBFUN xmlNotationPtr
  116. xmlAddNotationDecl (xmlValidCtxtPtr ctxt,
  117. xmlDtdPtr dtd,
  118. const xmlChar *name,
  119. const xmlChar *PublicID,
  120. const xmlChar *SystemID);
  121. #ifdef LIBXML_TREE_ENABLED
  122. XMLPUBFUN xmlNotationTablePtr
  123. xmlCopyNotationTable (xmlNotationTablePtr table);
  124. #endif /* LIBXML_TREE_ENABLED */
  125. XMLPUBFUN void
  126. xmlFreeNotationTable (xmlNotationTablePtr table);
  127. #ifdef LIBXML_OUTPUT_ENABLED
  128. XMLPUBFUN void
  129. xmlDumpNotationDecl (xmlBufferPtr buf,
  130. xmlNotationPtr nota);
  131. XMLPUBFUN void
  132. xmlDumpNotationTable (xmlBufferPtr buf,
  133. xmlNotationTablePtr table);
  134. #endif /* LIBXML_OUTPUT_ENABLED */
  135. /* Element Content */
  136. /* the non Doc version are being deprecated */
  137. XMLPUBFUN xmlElementContentPtr
  138. xmlNewElementContent (const xmlChar *name,
  139. xmlElementContentType type);
  140. XMLPUBFUN xmlElementContentPtr
  141. xmlCopyElementContent (xmlElementContentPtr content);
  142. XMLPUBFUN void
  143. xmlFreeElementContent (xmlElementContentPtr cur);
  144. /* the new versions with doc argument */
  145. XMLPUBFUN xmlElementContentPtr
  146. xmlNewDocElementContent (xmlDocPtr doc,
  147. const xmlChar *name,
  148. xmlElementContentType type);
  149. XMLPUBFUN xmlElementContentPtr
  150. xmlCopyDocElementContent(xmlDocPtr doc,
  151. xmlElementContentPtr content);
  152. XMLPUBFUN void
  153. xmlFreeDocElementContent(xmlDocPtr doc,
  154. xmlElementContentPtr cur);
  155. XMLPUBFUN void
  156. xmlSnprintfElementContent(char *buf,
  157. int size,
  158. xmlElementContentPtr content,
  159. int englob);
  160. #ifdef LIBXML_OUTPUT_ENABLED
  161. /* DEPRECATED */
  162. XMLPUBFUN void
  163. xmlSprintfElementContent(char *buf,
  164. xmlElementContentPtr content,
  165. int englob);
  166. #endif /* LIBXML_OUTPUT_ENABLED */
  167. /* DEPRECATED */
  168. /* Element */
  169. XMLPUBFUN xmlElementPtr
  170. xmlAddElementDecl (xmlValidCtxtPtr ctxt,
  171. xmlDtdPtr dtd,
  172. const xmlChar *name,
  173. xmlElementTypeVal type,
  174. xmlElementContentPtr content);
  175. #ifdef LIBXML_TREE_ENABLED
  176. XMLPUBFUN xmlElementTablePtr
  177. xmlCopyElementTable (xmlElementTablePtr table);
  178. #endif /* LIBXML_TREE_ENABLED */
  179. XMLPUBFUN void
  180. xmlFreeElementTable (xmlElementTablePtr table);
  181. #ifdef LIBXML_OUTPUT_ENABLED
  182. XMLPUBFUN void
  183. xmlDumpElementTable (xmlBufferPtr buf,
  184. xmlElementTablePtr table);
  185. XMLPUBFUN void
  186. xmlDumpElementDecl (xmlBufferPtr buf,
  187. xmlElementPtr elem);
  188. #endif /* LIBXML_OUTPUT_ENABLED */
  189. /* Enumeration */
  190. XMLPUBFUN xmlEnumerationPtr
  191. xmlCreateEnumeration (const xmlChar *name);
  192. XMLPUBFUN void
  193. xmlFreeEnumeration (xmlEnumerationPtr cur);
  194. #ifdef LIBXML_TREE_ENABLED
  195. XMLPUBFUN xmlEnumerationPtr
  196. xmlCopyEnumeration (xmlEnumerationPtr cur);
  197. #endif /* LIBXML_TREE_ENABLED */
  198. /* Attribute */
  199. XMLPUBFUN xmlAttributePtr
  200. xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,
  201. xmlDtdPtr dtd,
  202. const xmlChar *elem,
  203. const xmlChar *name,
  204. const xmlChar *ns,
  205. xmlAttributeType type,
  206. xmlAttributeDefault def,
  207. const xmlChar *defaultValue,
  208. xmlEnumerationPtr tree);
  209. #ifdef LIBXML_TREE_ENABLED
  210. XMLPUBFUN xmlAttributeTablePtr
  211. xmlCopyAttributeTable (xmlAttributeTablePtr table);
  212. #endif /* LIBXML_TREE_ENABLED */
  213. XMLPUBFUN void
  214. xmlFreeAttributeTable (xmlAttributeTablePtr table);
  215. #ifdef LIBXML_OUTPUT_ENABLED
  216. XMLPUBFUN void
  217. xmlDumpAttributeTable (xmlBufferPtr buf,
  218. xmlAttributeTablePtr table);
  219. XMLPUBFUN void
  220. xmlDumpAttributeDecl (xmlBufferPtr buf,
  221. xmlAttributePtr attr);
  222. #endif /* LIBXML_OUTPUT_ENABLED */
  223. /* IDs */
  224. XMLPUBFUN xmlIDPtr
  225. xmlAddID (xmlValidCtxtPtr ctxt,
  226. xmlDocPtr doc,
  227. const xmlChar *value,
  228. xmlAttrPtr attr);
  229. XMLPUBFUN void
  230. xmlFreeIDTable (xmlIDTablePtr table);
  231. XMLPUBFUN xmlAttrPtr
  232. xmlGetID (xmlDocPtr doc,
  233. const xmlChar *ID);
  234. XMLPUBFUN int
  235. xmlIsID (xmlDocPtr doc,
  236. xmlNodePtr elem,
  237. xmlAttrPtr attr);
  238. XMLPUBFUN int
  239. xmlRemoveID (xmlDocPtr doc,
  240. xmlAttrPtr attr);
  241. /* IDREFs */
  242. XML_DEPRECATED
  243. XMLPUBFUN xmlRefPtr
  244. xmlAddRef (xmlValidCtxtPtr ctxt,
  245. xmlDocPtr doc,
  246. const xmlChar *value,
  247. xmlAttrPtr attr);
  248. XML_DEPRECATED
  249. XMLPUBFUN void
  250. xmlFreeRefTable (xmlRefTablePtr table);
  251. XML_DEPRECATED
  252. XMLPUBFUN int
  253. xmlIsRef (xmlDocPtr doc,
  254. xmlNodePtr elem,
  255. xmlAttrPtr attr);
  256. XML_DEPRECATED
  257. XMLPUBFUN int
  258. xmlRemoveRef (xmlDocPtr doc,
  259. xmlAttrPtr attr);
  260. XML_DEPRECATED
  261. XMLPUBFUN xmlListPtr
  262. xmlGetRefs (xmlDocPtr doc,
  263. const xmlChar *ID);
  264. /**
  265. * The public function calls related to validity checking.
  266. */
  267. #ifdef LIBXML_VALID_ENABLED
  268. /* Allocate/Release Validation Contexts */
  269. XMLPUBFUN xmlValidCtxtPtr
  270. xmlNewValidCtxt(void);
  271. XMLPUBFUN void
  272. xmlFreeValidCtxt(xmlValidCtxtPtr);
  273. XMLPUBFUN int
  274. xmlValidateRoot (xmlValidCtxtPtr ctxt,
  275. xmlDocPtr doc);
  276. XMLPUBFUN int
  277. xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
  278. xmlDocPtr doc,
  279. xmlElementPtr elem);
  280. XMLPUBFUN xmlChar *
  281. xmlValidNormalizeAttributeValue(xmlDocPtr doc,
  282. xmlNodePtr elem,
  283. const xmlChar *name,
  284. const xmlChar *value);
  285. XMLPUBFUN xmlChar *
  286. xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt,
  287. xmlDocPtr doc,
  288. xmlNodePtr elem,
  289. const xmlChar *name,
  290. const xmlChar *value);
  291. XMLPUBFUN int
  292. xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
  293. xmlDocPtr doc,
  294. xmlAttributePtr attr);
  295. XMLPUBFUN int
  296. xmlValidateAttributeValue(xmlAttributeType type,
  297. const xmlChar *value);
  298. XMLPUBFUN int
  299. xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
  300. xmlDocPtr doc,
  301. xmlNotationPtr nota);
  302. XMLPUBFUN int
  303. xmlValidateDtd (xmlValidCtxtPtr ctxt,
  304. xmlDocPtr doc,
  305. xmlDtdPtr dtd);
  306. XMLPUBFUN int
  307. xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
  308. xmlDocPtr doc);
  309. XMLPUBFUN int
  310. xmlValidateDocument (xmlValidCtxtPtr ctxt,
  311. xmlDocPtr doc);
  312. XMLPUBFUN int
  313. xmlValidateElement (xmlValidCtxtPtr ctxt,
  314. xmlDocPtr doc,
  315. xmlNodePtr elem);
  316. XMLPUBFUN int
  317. xmlValidateOneElement (xmlValidCtxtPtr ctxt,
  318. xmlDocPtr doc,
  319. xmlNodePtr elem);
  320. XMLPUBFUN int
  321. xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
  322. xmlDocPtr doc,
  323. xmlNodePtr elem,
  324. xmlAttrPtr attr,
  325. const xmlChar *value);
  326. XMLPUBFUN int
  327. xmlValidateOneNamespace (xmlValidCtxtPtr ctxt,
  328. xmlDocPtr doc,
  329. xmlNodePtr elem,
  330. const xmlChar *prefix,
  331. xmlNsPtr ns,
  332. const xmlChar *value);
  333. XMLPUBFUN int
  334. xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
  335. xmlDocPtr doc);
  336. #endif /* LIBXML_VALID_ENABLED */
  337. #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
  338. XMLPUBFUN int
  339. xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
  340. xmlDocPtr doc,
  341. const xmlChar *notationName);
  342. #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */
  343. XMLPUBFUN int
  344. xmlIsMixedElement (xmlDocPtr doc,
  345. const xmlChar *name);
  346. XMLPUBFUN xmlAttributePtr
  347. xmlGetDtdAttrDesc (xmlDtdPtr dtd,
  348. const xmlChar *elem,
  349. const xmlChar *name);
  350. XMLPUBFUN xmlAttributePtr
  351. xmlGetDtdQAttrDesc (xmlDtdPtr dtd,
  352. const xmlChar *elem,
  353. const xmlChar *name,
  354. const xmlChar *prefix);
  355. XMLPUBFUN xmlNotationPtr
  356. xmlGetDtdNotationDesc (xmlDtdPtr dtd,
  357. const xmlChar *name);
  358. XMLPUBFUN xmlElementPtr
  359. xmlGetDtdQElementDesc (xmlDtdPtr dtd,
  360. const xmlChar *name,
  361. const xmlChar *prefix);
  362. XMLPUBFUN xmlElementPtr
  363. xmlGetDtdElementDesc (xmlDtdPtr dtd,
  364. const xmlChar *name);
  365. #ifdef LIBXML_VALID_ENABLED
  366. XMLPUBFUN int
  367. xmlValidGetPotentialChildren(xmlElementContent *ctree,
  368. const xmlChar **names,
  369. int *len,
  370. int max);
  371. XMLPUBFUN int
  372. xmlValidGetValidElements(xmlNode *prev,
  373. xmlNode *next,
  374. const xmlChar **names,
  375. int max);
  376. XMLPUBFUN int
  377. xmlValidateNameValue (const xmlChar *value);
  378. XMLPUBFUN int
  379. xmlValidateNamesValue (const xmlChar *value);
  380. XMLPUBFUN int
  381. xmlValidateNmtokenValue (const xmlChar *value);
  382. XMLPUBFUN int
  383. xmlValidateNmtokensValue(const xmlChar *value);
  384. #ifdef LIBXML_REGEXP_ENABLED
  385. /*
  386. * Validation based on the regexp support
  387. */
  388. XMLPUBFUN int
  389. xmlValidBuildContentModel(xmlValidCtxtPtr ctxt,
  390. xmlElementPtr elem);
  391. XMLPUBFUN int
  392. xmlValidatePushElement (xmlValidCtxtPtr ctxt,
  393. xmlDocPtr doc,
  394. xmlNodePtr elem,
  395. const xmlChar *qname);
  396. XMLPUBFUN int
  397. xmlValidatePushCData (xmlValidCtxtPtr ctxt,
  398. const xmlChar *data,
  399. int len);
  400. XMLPUBFUN int
  401. xmlValidatePopElement (xmlValidCtxtPtr ctxt,
  402. xmlDocPtr doc,
  403. xmlNodePtr elem,
  404. const xmlChar *qname);
  405. #endif /* LIBXML_REGEXP_ENABLED */
  406. #endif /* LIBXML_VALID_ENABLED */
  407. #ifdef __cplusplus
  408. }
  409. #endif
  410. #endif /* __XML_VALID_H__ */