kxml.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. /** @brief XML document (opaque type).
  12. *
  13. * The real type is defined by the selected external API.
  14. */
  15. typedef struct kxml_doc_s kxml_doc_t;
  16. /* @brief XML node (opaque type).
  17. *
  18. * The real type is defined by the selected external API.
  19. */
  20. typedef struct kxml_node_s kxml_node_t;
  21. /** @brief Start and Stop XML parser engine.
  22. *
  23. * Some parsers need a global cleanup at the end of the programm.
  24. */
  25. bool_t kxml_doc_start(void);
  26. bool_t kxml_doc_stop(void);
  27. /** @brief Read an XML document.
  28. */
  29. kxml_doc_t *kxml_doc_read(const char *filename);
  30. /** @brief Release a previously opened XML document.
  31. */
  32. void kxml_doc_release(kxml_doc_t *doc);
  33. /* @brief Validate a doc.
  34. *
  35. * Checks if a doc is valid (i.e. it loaded successfully).
  36. */
  37. bool_t kxml_doc_is_valid(const kxml_doc_t *doc);
  38. /** @brief Gets the document root.
  39. */
  40. kxml_node_t *kxml_doc_root(const kxml_doc_t *doc);
  41. /** @brief Gets error description, when available.
  42. */
  43. int kxml_doc_err_line(kxml_doc_t *doc);
  44. int kxml_doc_err_col(kxml_doc_t *doc);
  45. const char *kxml_doc_err_msg(kxml_doc_t *doc);
  46. /** @brief Node types.
  47. */
  48. typedef enum {
  49. KXML_NODE_DOC,
  50. KXML_NODE_ELM,
  51. KXML_NODE_TEXT,
  52. KXML_NODE_ATTR,
  53. KXML_NODE_COMMENT,
  54. KXML_NODE_PI,
  55. KXML_NODE_DECL,
  56. KXML_NODE_UNKNOWN,
  57. } kxml_nodetype_e;
  58. /** @brief Gets the node type.
  59. */
  60. kxml_nodetype_e kxml_node_type(const kxml_node_t *node);
  61. /** @brief Gets the next child or NULL.
  62. *
  63. * If curchild is NULL, then the function returns the first child.
  64. */
  65. const kxml_node_t *kxml_node_next_child(const kxml_node_t *parent,
  66. const kxml_node_t *curchild);
  67. /** @brief Gets the parent node.
  68. *
  69. * Returns NULL if node is the document root node.
  70. */
  71. kxml_node_t *kxml_node_parent(const kxml_node_t *node);
  72. /** @brief Gets the node name.
  73. */
  74. char *kxml_node_name(const kxml_node_t *node);
  75. void kxml_node_name_free(char *str);
  76. /** @brief Gets the node content.
  77. */
  78. char *kxml_node_content(const kxml_node_t *node);
  79. void kxml_node_content_free(char *str);
  80. /** @brief Gets an attribute by name.
  81. *
  82. * May return NULL if the attribute is not found
  83. */
  84. char *kxml_node_attr(const kxml_node_t *node, const char *attrname);
  85. void kxml_node_attr_free(char *str);
  86. /** @brief XML-helper
  87. */
  88. kscheme_t *kxml_load_scheme(const char *xml_path, faux_error_t *error);
  89. #endif // _klish_kxml_h