llxmlparser.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * @file llxmlparser.h
  3. * @brief LLXmlParser class definition
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLXMLPARSER_H
  33. #define LL_LLXMLPARSER_H
  34. #include "expat.h"
  35. #include "llpreprocessor.h"
  36. class LLXmlParser
  37. {
  38. protected:
  39. LOG_CLASS(LLXmlParser);
  40. public:
  41. LLXmlParser();
  42. virtual ~LLXmlParser();
  43. // Parses entire file
  44. bool parseFile(const std::string& path);
  45. // Parses some input. Returns 0 if a fatal error is detected. The last call
  46. // must have is_final true. len may be zero for this call (or any other).
  47. S32 parse(const char* buf, int len, int is_inal);
  48. const char* getErrorString();
  49. S32 getCurrentLineNumber();
  50. S32 getCurrentColumnNumber();
  51. LL_INLINE S32 getDepth() { return mDepth; }
  52. protected:
  53. // atts is an array of name/value pairs, terminated by 0; names and values
  54. // are 0 terminated.
  55. virtual void startElement(const char* name,
  56. const char** atts) {}
  57. virtual void endElement(const char* name) {}
  58. // s is not 0 terminated.
  59. virtual void characterData(const char* s, int len) {}
  60. // target and data are 0 terminated
  61. virtual void processingInstruction(const char* target,
  62. const char* data) {}
  63. // data is 0 terminated
  64. virtual void comment(const char* data) {}
  65. virtual void startCdataSection() {}
  66. virtual void endCdataSection() {}
  67. // This is called for any characters in the XML document for which there is
  68. // no applicable handler. This includes both characters that are part of
  69. // markup which is of a kind that is not reported (comments, markup
  70. // declarations), or characters that are part of a construct which could be
  71. // reported but for which no handler has been supplied. The characters are
  72. // passed exactly as they were in the XML document except that they will be
  73. // encoded in UTF-8. Line boundaries are not normalized. Note that a byte
  74. // order mark character is not passed to the default handler. There are no
  75. // guarantees about how characters are divided between calls to the default
  76. // handler: for example, a comment might be split between multiple calls.
  77. virtual void defaultData(const char* s, int len) {}
  78. // This is called for a declaration of an unparsed (NDATA) entity. The base
  79. // argument is whatever was set by XML_SetBase. The entity_name, system_id
  80. // and notation_name arguments will never be NULL. The other arguments may
  81. // be.
  82. virtual void unparsedEntityDecl(const char* entity_name, const char* base,
  83. const char* system_id,
  84. const char* public_id,
  85. const char* notation_name)
  86. {
  87. }
  88. public:
  89. ///////////////////////////////////////////////////////////////////////////
  90. // Pseudo-private methods. These are only used by internal callbacks.
  91. static void startElementHandler(void* user_data, const XML_Char* name,
  92. const XML_Char** atts);
  93. static void endElementHandler(void* user_data, const XML_Char* name);
  94. static void characterDataHandler(void* user_data, const XML_Char* s,
  95. int len);
  96. static void processingInstructionHandler(void* user_data,
  97. const XML_Char* target,
  98. const XML_Char* data);
  99. static void commentHandler(void* user_data, const XML_Char* data);
  100. static void startCdataSectionHandler(void* user_data);
  101. static void endCdataSectionHandler(void* user_data);
  102. static void defaultDataHandler(void* user_data, const XML_Char* s,
  103. int len);
  104. static void unparsedEntityDeclHandler(void* user_data,
  105. const XML_Char* entity_name,
  106. const XML_Char* base,
  107. const XML_Char* system_id,
  108. const XML_Char* public_id,
  109. const XML_Char* notation_name);
  110. protected:
  111. XML_Parser mParser;
  112. std::string mAuxErrorString;
  113. S32 mDepth;
  114. };
  115. #endif // LL_LLXMLPARSER_H