Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

dox/IO/vtkXMLParser.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkXMLParser.h,v $ 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00029 #ifndef __vtkXMLParser_h 00030 #define __vtkXMLParser_h 00031 00032 #include "vtkObject.h" 00033 00034 extern "C" 00035 { 00036 void vtkXMLParserStartElement(void*, const char*, const char**); 00037 void vtkXMLParserEndElement(void*, const char*); 00038 void vtkXMLParserCharacterDataHandler(void*, const char*, int); 00039 } 00040 00041 class VTK_IO_EXPORT vtkXMLParser : public vtkObject 00042 { 00043 public: 00044 vtkTypeRevisionMacro(vtkXMLParser,vtkObject); 00045 void PrintSelf(ostream& os, vtkIndent indent); 00046 00047 static vtkXMLParser* New(); 00048 00049 //BTX 00051 00052 vtkSetMacro(Stream, istream*); 00053 vtkGetMacro(Stream, istream*); 00055 00057 00060 long TellG(); 00061 void SeekG(long position); 00062 //ETX 00064 00066 virtual int Parse(); 00067 00069 00071 virtual int Parse(const char* inputString); 00072 virtual int Parse(const char* inputString, unsigned int length); 00074 00076 00081 virtual int InitializeParser(); 00082 virtual int ParseChunk(const char* inputString, unsigned int length); 00083 virtual int CleanupParser(); 00085 00087 00088 vtkSetStringMacro(FileName); 00089 vtkGetStringMacro(FileName); 00091 00092 protected: 00093 vtkXMLParser(); 00094 ~vtkXMLParser(); 00095 00096 // Input stream. Set by user. 00097 istream* Stream; 00098 00099 // File name to parse 00100 char* FileName; 00101 00102 // This variable is true if there was a parse error while parsing in 00103 // chunks. 00104 int ParseError; 00105 00106 // Character message to parse 00107 const char* InputString; 00108 int InputStringLength; 00109 00110 // Expat parser structure. Exists only during call to Parse(). 00111 void* Parser; 00112 00113 // Called by Parse() to read the stream and call ParseBuffer. Can 00114 // be replaced by subclasses to change how input is read. 00115 virtual int ParseXML(); 00116 00117 // Called before each block of input is read from the stream to 00118 // check if parsing is complete. Can be replaced by subclasses to 00119 // change the terminating condition for parsing. Parsing always 00120 // stops when the end of file is reached in the stream. 00121 virtual int ParsingComplete(); 00122 00123 // Called when a new element is opened in the XML source. Should be 00124 // replaced by subclasses to handle each element. 00125 // name = Name of new element. 00126 // atts = Null-terminated array of attribute name/value pairs. 00127 // Even indices are attribute names, and odd indices are values. 00128 virtual void StartElement(const char* name, const char** atts); 00129 00130 // Called at the end of an element in the XML source opened when 00131 // StartElement was called. 00132 virtual void EndElement(const char* name); 00133 00134 // Called when there is character data to handle. 00135 virtual void CharacterDataHandler(const char* data, int length); 00136 00137 // Called by begin handlers to report any stray attribute values. 00138 virtual void ReportStrayAttribute(const char* element, const char* attr, 00139 const char* value); 00140 00141 // Called by begin handlers to report any missing attribute values. 00142 virtual void ReportMissingAttribute(const char* element, const char* attr); 00143 00144 // Called by begin handlers to report bad attribute values. 00145 virtual void ReportBadAttribute(const char* element, const char* attr, 00146 const char* value); 00147 00148 // Called by StartElement to report unknown element type. 00149 virtual void ReportUnknownElement(const char* element); 00150 00151 // Called by Parse to report an XML syntax error. 00152 virtual void ReportXmlParseError(); 00153 00154 // Get the current byte index from the beginning of the XML stream. 00155 unsigned long GetXMLByteIndex(); 00156 00157 // Send the given buffer to the XML parser. 00158 virtual int ParseBuffer(const char* buffer, unsigned int count); 00159 00160 // Send the given c-style string to the XML parser. 00161 int ParseBuffer(const char* buffer); 00162 00163 // Utility for convenience of subclasses. Wraps isspace C library 00164 // routine. 00165 static int IsSpace(char c); 00166 00167 //BTX 00168 friend void vtkXMLParserStartElement(void*, const char*, const char**); 00169 friend void vtkXMLParserEndElement(void*, const char*); 00170 friend void vtkXMLParserCharacterDataHandler(void*, const char*, int); 00171 //ETX 00172 00173 private: 00174 vtkXMLParser(const vtkXMLParser&); // Not implemented. 00175 void operator=(const vtkXMLParser&); // Not implemented. 00176 }; 00177 00178 #endif