kxml.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /** @file kxml.h
  2. * @brief XML API for XML engines to provide.
  3. *
  4. * Don't use libfaux features here to be maximally independent from
  5. * specific libraries. It's just an interface API.
  6. */
  7. #ifndef _klish_kxml_h
  8. #define _klish_kxml_h
  9. #include <faux/faux.h>
  10. #include <klish/kscheme.h>
  11. #include <klish/kdb.h>
  12. /** @brief XML document (opaque type).
  13. *
  14. * The real type is defined by the selected external API.
  15. */
  16. typedef struct kxml_doc_s kxml_doc_t;
  17. /* @brief XML node (opaque type).
  18. *
  19. * The real type is defined by the selected external API.
  20. */
  21. typedef struct kxml_node_s kxml_node_t;
  22. /** @brief Start and Stop XML parser engine.
  23. *
  24. * Some parsers need a global cleanup at the end of the programm.
  25. */
  26. bool_t kxml_doc_start(void);
  27. bool_t kxml_doc_stop(void);
  28. /** @brief Read an XML document.
  29. */
  30. kxml_doc_t *kxml_doc_read(const char *filename);
  31. /** @brief Release a previously opened XML document.
  32. */
  33. void kxml_doc_release(kxml_doc_t *doc);
  34. /* @brief Validate a doc.
  35. *
  36. * Checks if a doc is valid (i.e. it loaded successfully).
  37. */
  38. bool_t kxml_doc_is_valid(const kxml_doc_t *doc);
  39. /** @brief Gets the document root.
  40. */
  41. kxml_node_t *kxml_doc_root(const kxml_doc_t *doc);
  42. /** @brief Gets error description, when available.
  43. */
  44. int kxml_doc_err_line(kxml_doc_t *doc);
  45. int kxml_doc_err_col(kxml_doc_t *doc);
  46. const char *kxml_doc_err_msg(kxml_doc_t *doc);
  47. /** @brief Node types.
  48. */
  49. typedef enum {
  50. KXML_NODE_DOC,
  51. KXML_NODE_ELM,
  52. KXML_NODE_TEXT,
  53. KXML_NODE_ATTR,
  54. KXML_NODE_COMMENT,
  55. KXML_NODE_PI,
  56. KXML_NODE_DECL,
  57. KXML_NODE_UNKNOWN,
  58. } kxml_nodetype_e;
  59. /** @brief Gets the node type.
  60. */
  61. kxml_nodetype_e kxml_node_type(const kxml_node_t *node);
  62. /** @brief Gets the next child or NULL.
  63. *
  64. * If curchild is NULL, then the function returns the first child.
  65. */
  66. const kxml_node_t *kxml_node_next_child(const kxml_node_t *parent,
  67. const kxml_node_t *curchild);
  68. /** @brief Gets the parent node.
  69. *
  70. * Returns NULL if node is the document root node.
  71. */
  72. kxml_node_t *kxml_node_parent(const kxml_node_t *node);
  73. /** @brief Gets the node name.
  74. */
  75. char *kxml_node_name(const kxml_node_t *node);
  76. void kxml_node_name_free(char *str);
  77. /** @brief Gets the node content.
  78. */
  79. char *kxml_node_content(const kxml_node_t *node);
  80. void kxml_node_content_free(char *str);
  81. /** @brief Gets an attribute by name.
  82. *
  83. * May return NULL if the attribute is not found
  84. */
  85. char *kxml_node_attr(const kxml_node_t *node, const char *attrname);
  86. void kxml_node_attr_free(char *str);
  87. /** @brief XML-helper
  88. */
  89. bool_t kxml_load_scheme(kscheme_t *scheme, const char *xml_path,
  90. faux_error_t *error);
  91. /** @brief Typical XML parser functions
  92. */
  93. bool_t kxml_plugin_init(kdb_t *db);
  94. bool_t kxml_plugin_fini(kdb_t *db);
  95. bool_t kxml_plugin_load_scheme(kdb_t *db, kscheme_t *scheme);
  96. #endif // _klish_kxml_h