kxml.h 2.4 KB

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