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