valid.h 13 KB

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