00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkXMLFile_h
00018 #define __itkXMLFile_h
00019 #include "itkLightProcessObject.h"
00020 #include "expat.h"
00021 #include <fstream>
00022
00023 namespace itk
00024 {
00025
00033 class
00034 XMLReaderBase : public LightProcessObject
00035 {
00036 public:
00038 itkSetStringMacro(Filename);
00039
00041 itkGetStringMacro(Filename);
00042
00044 virtual int CanReadFile(const char* name) = 0;
00045
00047 virtual void GenerateOutputInformation();
00048
00052 virtual void StartElement(const char * name,const char **atts) = 0;
00053
00057 virtual void EndElement(const char *name) = 0;
00058
00062 virtual void CharacterDataHandler(const char *inData, int inLength) = 0;
00063 protected:
00064
00069 void parse(void);
00070 std::string m_Filename;
00071 };
00072
00079 template <class T> class
00080 XMLReader : public XMLReaderBase
00081 {
00082 public:
00086 void SetOutputObject(T *obj) { m_OutputObject = obj; }
00087
00090 T *GetOutputObject(void) { return m_OutputObject; }
00091 protected:
00092 T *m_OutputObject;
00093 };
00094
00103 template <class T>
00104 class XMLWriterBase : public LightProcessObject
00105 {
00106 public:
00110 XMLWriterBase() {
00111 m_InputObject = 0;
00112 }
00113
00115 itkSetStringMacro(Filename);
00116
00118 itkGetStringMacro(Filename);
00119
00121 virtual int CanWriteFile(const char* name) = 0;
00122
00124 void SetObject(T *toWrite) { m_InputObject = toWrite; }
00125
00127 virtual int WriteFile() = 0;
00128
00130 void WriteStartElement(const char *const tag,std::ofstream &file)
00131 {
00132 file << '<' << tag << '>';
00133 }
00134
00136 void WriteEndElement(const char *const tag,std::ofstream &file)
00137 {
00138 file << '<' << '/' << tag << '>';
00139 }
00140
00142 void WriteCharacterData(const char *const data,std::ofstream &file)
00143 {
00144 file << data;
00145 }
00146
00148 void WriteStartElement(std::string &tag,std::ofstream &file)
00149 {
00150 WriteStartElement(tag.c_str(),file);
00151 }
00152
00154 void WriteEndElement(std::string &tag,std::ofstream &file)
00155 {
00156 WriteEndElement(tag.c_str(),file);
00157 }
00158
00160 void WriteCharacterData(std::string &data,std::ofstream &file)
00161 {
00162 WriteCharacterData(data.c_str(),file);
00163 }
00164 protected:
00165 T *m_InputObject;
00166 std::string m_Filename;
00167 };
00169
00170 }
00171 #endif
00172