1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmXMLParser.h,v $
6 Date: $Date: 2009-02-24 20:43:49 $
7 Version: $Revision: 1.6 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
20 #include "cmStandardIncludes.h"
24 void cmXMLParserStartElement(void*, const char*, const char**);
25 void cmXMLParserEndElement(void*, const char*);
26 void cmXMLParserCharacterDataHandler(void*, const char*, int);
29 /** \class cmXMLParser
30 * \brief Helper class for performing XML parsing
32 * Superclass for all XML parsers.
38 virtual ~cmXMLParser();
40 //! Parse given XML string
41 virtual int Parse(const char* string
);
43 //! Parse given XML file
44 virtual int ParseFile(const char* file
);
47 * When parsing fragments of XML or streaming XML, use the following
48 * three methods. InitializeParser method initialize parser but does
49 * not perform any actual parsing. ParseChunk parses framgent of
50 * XML. This has to match to what was already parsed. CleanupParser
51 * finishes parsing. If there were errors, CleanupParser will report
54 virtual int InitializeParser();
55 virtual int ParseChunk(const char* inputString
,
56 std::string::size_type length
);
57 virtual int CleanupParser();
60 //! This variable is true if there was a parse error while parsing in
64 //1 Expat parser structure. Exists only during call to Parse().
68 * Called before each block of input is read from the stream to check if
69 * parsing is complete. Can be replaced by subclasses to change the
70 * terminating condition for parsing. Parsing always stops when the end of
71 * file is reached in the stream.
74 virtual int ParsingComplete();
77 * Called when a new element is opened in the XML source. Should be
78 * replaced by subclasses to handle each element. name = Name of new
79 * element. atts = Null-terminated array of attribute name/value pairs.
80 * Even indices are attribute names, and odd indices are values.
82 virtual void StartElement(const char* name
, const char** atts
);
84 //! Called at the end of an element in the XML source opened when
85 //StartElement was called.
86 virtual void EndElement(const char* name
);
88 //! Called when there is character data to handle.
89 virtual void CharacterDataHandler(const char* data
, int length
);
91 //! Called by Parse to report an XML syntax error.
92 virtual void ReportXmlParseError();
94 /** Called by ReportXmlParseError with basic error info. */
95 virtual void ReportError(int line
, int column
, const char* msg
);
97 //! Utility for convenience of subclasses. Wraps isspace C library
99 static int IsSpace(char c
);
101 //! Send the given buffer to the XML parser.
102 virtual int ParseBuffer(const char* buffer
,
103 std::string::size_type length
);
105 //! Send the given c-style string to the XML parser.
106 int ParseBuffer(const char* buffer
);
108 /** Helps subclasses search for attributes on elements. */
109 static const char* FindAttribute(const char** atts
, const char* attribute
);
111 //! Callbacks for the expat
112 friend void cmXMLParserStartElement(void*, const char*, const char**);
113 friend void cmXMLParserEndElement(void*, const char*);
114 friend void cmXMLParserCharacterDataHandler(void*, const char*, int);