kxml.h 2.5 KB

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