bxml.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef bxml_H_INCLUDED
  2. #define bxml_H_INCLUDED
  3. #include "str.h"
  4. #include "ifa.h"
  5. /*
  6. * Kind of the BXML node. Can be : ATTR, TEXT, TAG.
  7. * Comments, entities and parsing instructions are ignored for now.
  8. * These values have been chosen to be greater that parser state values.
  9. */
  10. enum BXMLKind_
  11. {
  12. /* Root node */
  13. BXML_ROOT = 100,
  14. /* Normal tag*/
  15. BXML_TAG = 101,
  16. /* Text node. */
  17. BXML_TEXT = 102,
  18. /* Comment node. */
  19. BXML_COMMENT = 104,
  20. /* Declare node. */
  21. BXML_DECLARE = 105,
  22. BXML_LASTKIND = 106,
  23. };
  24. typedef struct Bxml_ Bxml;
  25. typedef struct BxmlAttribute_ BxmlAttribute;
  26. typedef struct BxmlBuffer_ BxmlBuffer;
  27. struct BxmlAttribute_ {
  28. char * name;
  29. char * value;
  30. BxmlAttribute * next;
  31. };
  32. struct BxmlBuffer_ {
  33. char * text;
  34. size_t size;
  35. size_t space;
  36. };
  37. struct Bxml_ {
  38. int kind; /* Kind of tag. */
  39. char * name; /* Tag name. #text for text nodes. */
  40. char * text; /* Tag text content, NULL if none. */
  41. BxmlAttribute * attributes; /* First of linked list of tag attributes. */
  42. BxmlAttribute * last_attr; /* Last atrribute. */
  43. Bxml * sibling; /* Sibling tag. */
  44. Bxml * child; /* First child tag, NULL if none */
  45. Bxml * parent; /* Parent tag, NULL if current tag is root tag */
  46. int flags; /* Additional status flags. */
  47. };
  48. Bxml * bxml_child(Bxml * xml, const char *name);
  49. Bxml * bxml_sibling(Bxml * xml);
  50. Bxml * bxml_next(Bxml * xml);
  51. char * bxml_text(Bxml * xml);
  52. char * bxml_name(Bxml * xml);
  53. Bxml * bxml_index(Bxml * xml);
  54. char * bxml_attribute(Bxml * xml, const char * name);
  55. Bxml * bxml_get(Bxml * xml, ...);
  56. char * bxml_to_str(Bxml * xml);
  57. char ** bxml_processing_instructions(Bxml * xml);
  58. char * bxml_error(Bxml * xml);
  59. Bxml * bxml_free(Bxml * xml);
  60. Bxml * bxml_new(int kind, ...);
  61. Bxml * bxml_new_va(int kind, va_list args);
  62. Bxml * bxml_new_size_va(int kind, int size, va_list args);
  63. Bxml * bxml_new_size(int kind, int size, ...);
  64. Bxml * bxml_add_child(Bxml * xml, Bxml * child);
  65. Bxml * bxml_new_child_va(Bxml * xml, int kind, va_list args);
  66. Bxml * bxml_new_child(Bxml * xml, int kind, ...);
  67. Bxml * bxml_merge_text(Bxml * text1, Bxml * text2);
  68. Bxml * bxml_merge_adjacent_text(Bxml * text1, Bxml * text2);
  69. Bxml * bxml_get_last_sibling(Bxml * me);
  70. Bxml * bxml_get_last_child(Bxml * me);
  71. Bxml * bxml_append_sibling(Bxml * me, Bxml * you);
  72. Bxml * bxml_get_sibling_at(Bxml * me, int pos);
  73. Bxml * bxml_get_child_at(Bxml * me, int pos);
  74. BxmlAttribute *
  75. bxml_set_attribute(Bxml * xml, char *name, char *value);
  76. Bxml * bxml_append_buf(Bxml * me, char * buf, int bufsize);
  77. BxmlAttribute * bxml_new_attribute_size(Bxml * me, char * name, int namesize, char * value, int valuesize);
  78. BxmlAttribute * bxml_new_attribute(Bxml * me, char * name, char * value);
  79. BxmlAttribute * bxml_get_attribute_pointer(Bxml * me, char * name);
  80. char * bxml_get_attribute(Bxml * me, char * name);
  81. Bxml * bxml_parse_str(char * str);
  82. Bxml * bxml_parse_buf(char * str, size_t len);
  83. Bxml * bxml_parse_file(FILE * file);
  84. Bxml * bxml_parse_filename(char * filename);
  85. void bxml_print_element_names(Bxml * node);
  86. void bxml_print_all_attributes(Bxml * node);
  87. Bxml * bxml_find_next_kind(Bxml * node, const char * name, int kind);
  88. Bxml * bxml_find_next(Bxml * node, const char * name);
  89. Bxml * bxml_find_child_kind(Bxml * node, const char * name, int kind);
  90. Bxml * bxml_find_child(Bxml * node, const char * name);
  91. Bxml * bxml_find_child_deep_va(Bxml * node, va_list args);
  92. Bxml * bxml_find_child_deep(Bxml * node, ...);
  93. long * bxml_get_attribute_long(Bxml * node, char * name, long * result);
  94. double * bxml_get_attribute_double(Bxml * node, char * name, double * result);
  95. Bxml * bxml_get_text_tag_under(Bxml * node);
  96. char * bxml_get_text_under(Bxml * node);
  97. int bxml_show_to(Bxml * xml, FILE * out, int depth);
  98. #endif