9
3

my_xml.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (c) 2000, 2002, 2003, 2005, 2007 MySQL AB
  2. Use is subject to license terms
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
  13. #ifndef _my_xml_h
  14. #define _my_xml_h
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #define MY_XML_OK 0
  19. #define MY_XML_ERROR 1
  20. /*
  21. A flag whether to use absolute tag names in call-back functions,
  22. like "a", "a.b" and "a.b.c" (used in character set file parser),
  23. or relative names like "a", "b" and "c".
  24. */
  25. #define MY_XML_FLAG_RELATIVE_NAMES 1
  26. /*
  27. A flag whether to skip normilization of text values before calling
  28. call-back functions: i.e. skip leading/trailing spaces,
  29. \r, \n, \t characters.
  30. */
  31. #define MY_XML_FLAG_SKIP_TEXT_NORMALIZATION 2
  32. enum my_xml_node_type
  33. {
  34. MY_XML_NODE_TAG, /* can have TAG, ATTR and TEXT children */
  35. MY_XML_NODE_ATTR, /* can have TEXT children */
  36. MY_XML_NODE_TEXT /* cannot have children */
  37. };
  38. typedef struct xml_stack_st
  39. {
  40. int flags;
  41. enum my_xml_node_type current_node_type;
  42. char errstr[128];
  43. struct {
  44. char static_buffer[128];
  45. char *buffer;
  46. size_t buffer_size;
  47. char *start;
  48. char *end;
  49. } attr;
  50. const char *beg;
  51. const char *cur;
  52. const char *end;
  53. void *user_data;
  54. int (*enter)(struct xml_stack_st *st,const char *val, size_t len);
  55. int (*value)(struct xml_stack_st *st,const char *val, size_t len);
  56. int (*leave_xml)(struct xml_stack_st *st,const char *val, size_t len);
  57. } MY_XML_PARSER;
  58. void my_xml_parser_create(MY_XML_PARSER *st);
  59. void my_xml_parser_free(MY_XML_PARSER *st);
  60. int my_xml_parse(MY_XML_PARSER *st,const char *str, size_t len);
  61. void my_xml_set_value_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *,
  62. const char *,
  63. size_t len));
  64. void my_xml_set_enter_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *,
  65. const char *,
  66. size_t len));
  67. void my_xml_set_leave_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *,
  68. const char *,
  69. size_t len));
  70. void my_xml_set_user_data(MY_XML_PARSER *st, void *);
  71. size_t my_xml_error_pos(MY_XML_PARSER *st);
  72. uint my_xml_error_lineno(MY_XML_PARSER *st);
  73. const char *my_xml_error_string(MY_XML_PARSER *st);
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* _my_xml_h */