Simple XML subset parser comparable to glib's Markup parser, but without any dependencies in one self contained file. Forked from https://github.com/ooxi/xml.c
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

131 строка
3.0 KiB

  1. /**
  2. * Copyright (c) 2012 ooxi/xml.c
  3. * https://github.com/ooxi/xml.c
  4. *
  5. * This software is provided 'as-is', without any express or implied warranty.
  6. * In no event will the authors be held liable for any damages arising from the
  7. * use of this software.
  8. *
  9. * Permission is granted to anyone to use this software for any purpose,
  10. * including commercial applications, and to alter it and redistribute it
  11. * freely, subject to the following restrictions:
  12. *
  13. * 1. The origin of this software must not be misrepresented; you must not
  14. * claim that you wrote the original software. If you use this software in a
  15. * product, an acknowledgment in the product documentation would be
  16. * appreciated but is not required.
  17. *
  18. * 2. Altered source versions must be plainly marked as such, and must not be
  19. * misrepresented as being the original software.
  20. *
  21. * 3. This notice may not be removed or altered from any source distribution.
  22. */
  23. #ifndef HEADER_GLTOOLKIT_XML
  24. #define HEADER_GLTOOLKIT_XML
  25. /**
  26. * Includes
  27. */
  28. #include <stdint.h>
  29. #include <string.h>
  30. /**
  31. * Opaque structure holding the parsed xml document
  32. */
  33. struct xml_document;
  34. struct xml_node;
  35. /**
  36. * Internal character sequence representation
  37. */
  38. struct xml_string;
  39. /**
  40. * Tries to parse the XML fragment in buffer
  41. *
  42. * @param buffer Chunk to parse
  43. * @param length Size of the buffer
  44. *
  45. * @warning `buffer` will be referenced by the document, you may not free it
  46. * until you free the xml_document
  47. * @warning You have to call xml_free after you finished using the document
  48. *
  49. * @return The parsed xml fragment iff `parsing was successful
  50. */
  51. struct xml_document* xml_parse_document(uint8_t* buffer, size_t length);
  52. /**
  53. * Frees all resources associated with the document. All xml_node and xml_string
  54. * references obtained through the document will be invalidated
  55. *
  56. * @param document xml_document to free
  57. * @param free_buffer iff true the internal buffer supplied via xml_parse_buffer
  58. * will be freed with the `free` system call
  59. */
  60. void xml_document_free(struct xml_document* document, _Bool free_buffer);
  61. /**
  62. * @return xml_node representing the document root
  63. */
  64. struct xml_node* xml_document_root(struct xml_document* document);
  65. /**
  66. * @return The xml_node's tag name
  67. */
  68. struct xml_string* xml_node_name(struct xml_node* node);
  69. /**
  70. * @return The xml_node's string content (if available, otherwise NULL)
  71. */
  72. struct xml_string* xml_node_content(struct xml_node* node);
  73. /**
  74. * @return Number of child nodes
  75. */
  76. size_t xml_node_children(struct xml_node* node);
  77. /**
  78. * @return The n-th child or 0 if out of range
  79. */
  80. struct xml_node* xml_node_child(struct xml_node* node, size_t child);
  81. /**
  82. * @return Length of the string
  83. */
  84. size_t xml_string_length(struct xml_string* string);
  85. /**
  86. * Copies the string into the supplied buffer
  87. *
  88. * @warning String will not be 0-terminated
  89. * @warning Will write at most length bytes, even if the string is longer
  90. */
  91. void xml_string_copy(struct xml_string* string, uint8_t* buffer, size_t length);
  92. #endif