CCSAXParser.h 3.0 KB

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