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

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 =========================================================================*/
00040 #ifndef __vtkXMLParser_h
00041 #define __vtkXMLParser_h
00042 
00043 #include "vtkObject.h"
00044 
00045 extern "C"
00046 {
00047   void vtkXMLParserStartElement(void*, const char*, const char**);
00048   void vtkXMLParserEndElement(void*, const char*);
00049   void vtkXMLParserCharacterDataHandler(void*, const char*, int);
00050 }
00051 
00052 class VTK_IO_EXPORT vtkXMLParser : public vtkObject
00053 {
00054 public:
00055   vtkTypeRevisionMacro(vtkXMLParser,vtkObject);
00056   void PrintSelf(ostream& os, vtkIndent indent);
00057 
00058   static vtkXMLParser* New();
00059 
00060   //BTX
00062 
00063   vtkSetMacro(Stream, istream*);
00064   vtkGetMacro(Stream, istream*);
00066 
00068 
00071   long TellG();
00072   void SeekG(long position);
00073   //ETX
00075 
00077   virtual int Parse();
00078 
00080 
00082   virtual int Parse(const char* inputString);
00083   virtual int Parse(const char* inputString, unsigned int length);
00085 
00087 
00092   virtual int InitializeParser();
00093   virtual int ParseChunk(const char* inputString, unsigned int length);
00094   virtual int CleanupParser();
00096 
00098 
00099   vtkSetStringMacro(FileName);
00100   vtkGetStringMacro(FileName);
00102 
00103 protected:
00104   vtkXMLParser();
00105   ~vtkXMLParser();
00106 
00107   // Input stream.  Set by user.
00108   istream* Stream;
00109 
00110   // File name to parse
00111   char* FileName;
00112 
00113   // This variable is true if there was a parse error while parsing in
00114   // chunks.
00115   int ParseError;
00116 
00117   // Character message to parse
00118   const char* InputString;
00119   int InputStringLength;
00120 
00121   // Expat parser structure.  Exists only during call to Parse().
00122   void* Parser;
00123 
00124   // Called by Parse() to read the stream and call ParseBuffer.  Can
00125   // be replaced by subclasses to change how input is read.
00126   virtual int ParseXML();
00127 
00128   // Called before each block of input is read from the stream to
00129   // check if parsing is complete.  Can be replaced by subclasses to
00130   // change the terminating condition for parsing.  Parsing always
00131   // stops when the end of file is reached in the stream.
00132   virtual int ParsingComplete();
00133 
00134   // Called when a new element is opened in the XML source.  Should be
00135   // replaced by subclasses to handle each element.
00136   //  name = Name of new element.
00137   //  atts = Null-terminated array of attribute name/value pairs.
00138   //         Even indices are attribute names, and odd indices are values.
00139   virtual void StartElement(const char* name, const char** atts);
00140 
00141   // Called at the end of an element in the XML source opened when
00142   // StartElement was called.
00143   virtual void EndElement(const char* name);
00144 
00145   // Called when there is character data to handle.
00146   virtual void CharacterDataHandler(const char* data, int length);
00147 
00148   // Called by begin handlers to report any stray attribute values.
00149   virtual void ReportStrayAttribute(const char* element, const char* attr,
00150                                     const char* value);
00151 
00152   // Called by begin handlers to report any missing attribute values.
00153   virtual void ReportMissingAttribute(const char* element, const char* attr);
00154 
00155   // Called by begin handlers to report bad attribute values.
00156   virtual void ReportBadAttribute(const char* element, const char* attr,
00157                                   const char* value);
00158 
00159   // Called by StartElement to report unknown element type.
00160   virtual void ReportUnknownElement(const char* element);
00161 
00162   // Called by Parse to report an XML syntax error.
00163   virtual void ReportXmlParseError();
00164 
00165   // Get the current byte index from the beginning of the XML stream.
00166   unsigned long GetXMLByteIndex();
00167 
00168   // Send the given buffer to the XML parser.
00169   virtual int ParseBuffer(const char* buffer, unsigned int count);
00170 
00171   // Send the given c-style string to the XML parser.
00172   int ParseBuffer(const char* buffer);
00173 
00174   // Utility for convenience of subclasses.  Wraps isspace C library
00175   // routine.
00176   static int IsSpace(char c);
00177 
00178   //BTX
00179   friend void vtkXMLParserStartElement(void*, const char*, const char**);
00180   friend void vtkXMLParserEndElement(void*, const char*);
00181   friend void vtkXMLParserCharacterDataHandler(void*, const char*, int);
00182   //ETX
00183 
00184 private:
00185   vtkXMLParser(const vtkXMLParser&);  // Not implemented.
00186   void operator=(const vtkXMLParser&);  // Not implemented.
00187 };
00188 
00189 #endif