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

IO/vtkXMLParser.h

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