PageRenderTime 35ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/llxml/llxmlparser.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 133 lines | 58 code | 23 blank | 52 comment | 0 complexity | aecee5aa7b80a2dea0f8f723d0e1911c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llxmlparser.h
  3. * @brief LLXmlParser class definition
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLXMLPARSER_H
  27. #define LL_LLXMLPARSER_H
  28. #ifndef XML_STATIC
  29. #define XML_STATIC
  30. #endif
  31. #ifdef LL_STANDALONE
  32. #include <expat.h>
  33. #else
  34. #include "expat/expat.h"
  35. #endif
  36. class LLXmlParser
  37. {
  38. public:
  39. LLXmlParser();
  40. virtual ~LLXmlParser();
  41. // Parses entire file
  42. BOOL parseFile(const std::string &path);
  43. // Parses some input. Returns 0 if a fatal error is detected.
  44. // The last call must have isFinal true;
  45. // len may be zero for this call (or any other).
  46. S32 parse( const char* buf, int len, int isFinal );
  47. const char* getErrorString();
  48. S32 getCurrentLineNumber();
  49. S32 getCurrentColumnNumber();
  50. S32 getDepth() { return mDepth; }
  51. protected:
  52. // atts is array of name/value pairs, terminated by 0;
  53. // names and values are 0 terminated.
  54. virtual void startElement(const char *name, const char **atts) {}
  55. virtual void endElement(const char *name) {}
  56. // s is not 0 terminated.
  57. virtual void characterData(const char *s, int len) {}
  58. // target and data are 0 terminated
  59. virtual void processingInstruction(const char *target, const char *data) {}
  60. // data is 0 terminated
  61. virtual void comment(const char *data) {}
  62. virtual void startCdataSection() {}
  63. virtual void endCdataSection() {}
  64. // This is called for any characters in the XML document for
  65. // which there is no applicable handler. This includes both
  66. // characters that are part of markup which is of a kind that is
  67. // not reported (comments, markup declarations), or characters
  68. // that are part of a construct which could be reported but
  69. // for which no handler has been supplied. The characters are passed
  70. // exactly as they were in the XML document except that
  71. // they will be encoded in UTF-8. Line boundaries are not normalized.
  72. // Note that a byte order mark character is not passed to the default handler.
  73. // There are no guarantees about how characters are divided between calls
  74. // to the default handler: for example, a comment might be split between
  75. // multiple calls.
  76. virtual void defaultData(const char *s, int len) {}
  77. // This is called for a declaration of an unparsed (NDATA)
  78. // entity. The base argument is whatever was set by XML_SetBase.
  79. // The entityName, systemId and notationName arguments will never be null.
  80. // The other arguments may be.
  81. virtual void unparsedEntityDecl(
  82. const char *entityName,
  83. const char *base,
  84. const char *systemId,
  85. const char *publicId,
  86. const char *notationName) {}
  87. public:
  88. ///////////////////////////////////////////////////////////////////////////////
  89. // Pseudo-private methods. These are only used by internal callbacks.
  90. static void startElementHandler(void *userData, const XML_Char *name, const XML_Char **atts);
  91. static void endElementHandler(void *userData, const XML_Char *name);
  92. static void characterDataHandler(void *userData, const XML_Char *s, int len);
  93. static void processingInstructionHandler(void *userData, const XML_Char *target, const XML_Char *data);
  94. static void commentHandler(void *userData, const XML_Char *data);
  95. static void startCdataSectionHandler(void *userData);
  96. static void endCdataSectionHandler(void *userData);
  97. static void defaultDataHandler( void *userData, const XML_Char *s, int len);
  98. static void unparsedEntityDeclHandler(
  99. void *userData,
  100. const XML_Char *entityName,
  101. const XML_Char *base,
  102. const XML_Char *systemId,
  103. const XML_Char *publicId,
  104. const XML_Char *notationName);
  105. protected:
  106. XML_Parser mParser;
  107. int mDepth;
  108. std::string mAuxErrorString;
  109. };
  110. #endif // LL_LLXMLPARSER_H