cmXMLParser.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 three
  38. * methods. InitializeParser method initialize parser but does not perform
  39. * any actual parsing. ParseChunk parses framgent of XML. This has to match
  40. * to what was already parsed. CleanupParser finishes parsing. If there were
  41. * errors, CleanupParser will report them.
  42. */
  43. virtual int InitializeParser();
  44. virtual int ParseChunk(const char* inputString, unsigned int length);
  45. virtual int CleanupParser();
  46. protected:
  47. //! This variable is true if there was a parse error while parsing in chunks.
  48. int ParseError;
  49. //1 Expat parser structure. Exists only during call to Parse().
  50. void* Parser;
  51. /**
  52. * Called before each block of input is read from the stream to check if
  53. * parsing is complete. Can be replaced by subclasses to change the
  54. * terminating condition for parsing. Parsing always stops when the end of
  55. * file is reached in the stream.
  56. */
  57. virtual int ParsingComplete();
  58. /**
  59. * Called when a new element is opened in the XML source. Should be replaced
  60. * by subclasses to handle each element.
  61. * name = Name of new element.
  62. * atts = Null-terminated array of attribute name/value pairs. Even
  63. * indices are attribute names, and odd indices are values.
  64. */
  65. virtual void StartElement(const char* name, const char** atts);
  66. //! Called at the end of an element in the XML source opened when StartElement
  67. // was called.
  68. virtual void EndElement(const char* name);
  69. //! Called when there is character data to handle.
  70. virtual void CharacterDataHandler(const char* data, int length);
  71. //! Called by Parse to report an XML syntax error.
  72. virtual void ReportXmlParseError();
  73. //! Utility for convenience of subclasses. Wraps isspace C library
  74. // routine.
  75. static int IsSpace(char c);
  76. //! Send the given buffer to the XML parser.
  77. virtual int ParseBuffer(const char* buffer, unsigned int count);
  78. //! Send the given c-style string to the XML parser.
  79. int ParseBuffer(const char* buffer);
  80. //! Callbacks for the expat
  81. friend void cmXMLParserStartElement(void*, const char*, const char**);
  82. friend void cmXMLParserEndElement(void*, const char*);
  83. friend void cmXMLParserCharacterDataHandler(void*, const char*, int);
  84. };
  85. #endif