CCSAXParser.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /****************************************************************************
  2. Copyright (c) 2010 cocos2d-x.org
  3. Copyright (c) 2010 Максим Аксенов
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CCSAXPARSER_H__
  22. #define __CCSAXPARSER_H__
  23. /// @cond DO_NOT_SHOW
  24. #include "platform/CCPlatformConfig.h"
  25. #include "platform/CCCommon.h"
  26. #include <string>
  27. NS_CC_BEGIN
  28. /**
  29. * @addtogroup platform
  30. * @{
  31. */
  32. typedef unsigned char CC_XML_CHAR;
  33. class CC_DLL SAXDelegator
  34. {
  35. public:
  36. virtual ~SAXDelegator() {}
  37. /**
  38. * @js NA
  39. * @lua NA
  40. */
  41. virtual void startElement(void *ctx, const char *name, const char **atts) = 0;
  42. /**
  43. * @js NA
  44. * @lua NA
  45. */
  46. virtual void endElement(void *ctx, const char *name) = 0;
  47. /**
  48. * @js NA
  49. * @lua NA
  50. */
  51. virtual void textHandler(void *ctx, const char *s, size_t len) = 0;
  52. };
  53. class CC_DLL SAXParser
  54. {
  55. SAXDelegator* _delegator;
  56. public:
  57. /**
  58. * @js NA
  59. * @lua NA
  60. */
  61. SAXParser();
  62. /**
  63. * @js NA
  64. * @lua NA
  65. */
  66. ~SAXParser(void);
  67. /**
  68. * @js NA
  69. * @lua NA
  70. */
  71. bool init(const char *encoding);
  72. /**
  73. * @js NA
  74. * @lua NA
  75. */
  76. bool parse(const char* xmlData, size_t dataLength);
  77. /**
  78. * @js NA
  79. * @lua NA
  80. */
  81. bool parse(const std::string& filename);
  82. /**
  83. * New API for performance.
  84. */
  85. bool parseIntrusive(char* xmlData, size_t dataLength);
  86. /**
  87. * @js NA
  88. * @lua NA
  89. */
  90. void setDelegator(SAXDelegator* delegator);
  91. /**
  92. * @js NA
  93. * @lua NA
  94. */
  95. static void startElement(void *ctx, const CC_XML_CHAR *name, const CC_XML_CHAR **atts);
  96. /**
  97. * @js NA
  98. * @lua NA
  99. */
  100. static void endElement(void *ctx, const CC_XML_CHAR *name);
  101. /**
  102. * @js NA
  103. * @lua NA
  104. */
  105. static void textHandler(void *ctx, const CC_XML_CHAR *name, size_t len);
  106. };
  107. // end of platform group
  108. /// @}
  109. NS_CC_END
  110. /// @endcond
  111. #endif //__CCSAXPARSER_H__