1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
15 #include "cmStandardIncludes.h"
19 void cmXMLParserStartElement(void*, const char*, const char**);
20 void cmXMLParserEndElement(void*, const char*);
21 void cmXMLParserCharacterDataHandler(void*, const char*, int);
24 /** \class cmXMLParser
25 * \brief Helper class for performing XML parsing
27 * Superclass for all XML parsers.
33 virtual ~cmXMLParser();
35 //! Parse given XML string
36 virtual int Parse(const char* string);
38 //! Parse given XML file
39 virtual int ParseFile(const char* file);
42 * When parsing fragments of XML or streaming XML, use the following
43 * three methods. InitializeParser method initialize parser but does
44 * not perform any actual parsing. ParseChunk parses framgent of
45 * XML. This has to match to what was already parsed. CleanupParser
46 * finishes parsing. If there were errors, CleanupParser will report
49 virtual int InitializeParser();
50 virtual int ParseChunk(const char* inputString,
51 std::string::size_type length);
52 virtual int CleanupParser();
55 //! This variable is true if there was a parse error while parsing in
59 //1 Expat parser structure. Exists only during call to Parse().
63 * Called before each block of input is read from the stream to check if
64 * parsing is complete. Can be replaced by subclasses to change the
65 * terminating condition for parsing. Parsing always stops when the end of
66 * file is reached in the stream.
69 virtual int ParsingComplete();
72 * Called when a new element is opened in the XML source. Should be
73 * replaced by subclasses to handle each element. name = Name of new
74 * element. atts = Null-terminated array of attribute name/value pairs.
75 * Even indices are attribute names, and odd indices are values.
77 virtual void StartElement(const char* name, const char** atts);
79 //! Called at the end of an element in the XML source opened when
80 //StartElement was called.
81 virtual void EndElement(const char* name);
83 //! Called when there is character data to handle.
84 virtual void CharacterDataHandler(const char* data, int length);
86 //! Called by Parse to report an XML syntax error.
87 virtual void ReportXmlParseError();
89 /** Called by ReportXmlParseError with basic error info. */
90 virtual void ReportError(int line, int column, const char* msg);
92 //! Utility for convenience of subclasses. Wraps isspace C library
94 static int IsSpace(char c);
96 //! Send the given buffer to the XML parser.
97 virtual int ParseBuffer(const char* buffer,
98 std::string::size_type length);
100 //! Send the given c-style string to the XML parser.
101 int ParseBuffer(const char* buffer);
103 /** Helps subclasses search for attributes on elements. */
104 static const char* FindAttribute(const char** atts, const char* attribute);
106 //! Callbacks for the expat
107 friend void cmXMLParserStartElement(void*, const char*, const char**);
108 friend void cmXMLParserEndElement(void*, const char*);
109 friend void cmXMLParserCharacterDataHandler(void*, const char*, int);