cmXMLParser.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmXMLParser_h
  14. #define cmXMLParser_h
  15. #include "cmStandardIncludes.h"
  16. extern "C"
  17. {
  18. void cmXMLParserStartElement(void*, const char*, const char**);
  19. void cmXMLParserEndElement(void*, const char*);
  20. void cmXMLParserCharacterDataHandler(void*, const char*, int);
  21. }
  22. /** \class cmXMLParser
  23. * \brief Helper class for performing XML parsing
  24. *
  25. * Superclass for all XML parsers.
  26. */
  27. class cmXMLParser
  28. {
  29. public:
  30. cmXMLParser();
  31. virtual ~cmXMLParser();
  32. //! Parse given XML string
  33. virtual int Parse(const char* string);
  34. //! Parse given XML file
  35. virtual int ParseFile(const char* file);
  36. /**
  37. * When parsing fragments of XML or streaming XML, use the following
  38. * three methods. InitializeParser method initialize parser but does
  39. * not perform any actual parsing. ParseChunk parses framgent of
  40. * XML. This has to match to what was already parsed. CleanupParser
  41. * finishes parsing. If there were errors, CleanupParser will report
  42. * them.
  43. */
  44. virtual int InitializeParser();
  45. virtual int ParseChunk(const char* inputString, unsigned int length);
  46. virtual int CleanupParser();
  47. protected:
  48. //! This variable is true if there was a parse error while parsing in
  49. //chunks.
  50. int ParseError;
  51. //1 Expat parser structure. Exists only during call to Parse().
  52. void* Parser;
  53. /**
  54. * Called before each block of input is read from the stream to check if
  55. * parsing is complete. Can be replaced by subclasses to change the
  56. * terminating condition for parsing. Parsing always stops when the end of
  57. * file is reached in the stream.
  58. */
  59. virtual int ParsingComplete();
  60. /**
  61. * Called when a new element is opened in the XML source. Should be
  62. * replaced by subclasses to handle each element. name = Name of new
  63. * element. atts = Null-terminated array of attribute name/value pairs.
  64. * Even indices are attribute names, and odd indices are values.
  65. */
  66. virtual void StartElement(const char* name, const char** atts);
  67. //! Called at the end of an element in the XML source opened when
  68. //StartElement was called.
  69. virtual void EndElement(const char* name);
  70. //! Called when there is character data to handle.
  71. virtual void CharacterDataHandler(const char* data, int length);
  72. //! Called by Parse to report an XML syntax error.
  73. virtual void ReportXmlParseError();
  74. //! Utility for convenience of subclasses. Wraps isspace C library
  75. // routine.
  76. static int IsSpace(char c);
  77. //! Send the given buffer to the XML parser.
  78. virtual int ParseBuffer(const char* buffer, unsigned int count);
  79. //! Send the given c-style string to the XML parser.
  80. int ParseBuffer(const char* buffer);
  81. //! Callbacks for the expat
  82. friend void cmXMLParserStartElement(void*, const char*, const char**);
  83. friend void cmXMLParserEndElement(void*, const char*);
  84. friend void cmXMLParserCharacterDataHandler(void*, const char*, int);
  85. };
  86. #endif