Clone of PhatAC @ https://github.com/floaterxk/PhatAC

my_xml.h 2.8KB

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