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;
00046 virtual void GenerateOutputInformation();
00050 virtual void StartElement(const char * name,const char **atts) = 0;
00054 virtual void EndElement(const char *name) = 0;
00058 virtual void CharacterDataHandler(const char *inData, int inLength) = 0;
00059 protected:
00064 void parse(void);
00065 std::string m_Filename;
00066 };
00067
00074 template <class T> class
00075 XMLReader : public XMLReaderBase
00076 {
00077 public:
00081 void SetOutputObject(T *obj) { m_OutputObject = obj; }
00084 T *GetOutputObject(void) { return m_OutputObject; }
00085 protected:
00086 T *m_OutputObject;
00087 };
00088
00097 template <class T>
00098 class XMLWriterBase : public LightProcessObject
00099 {
00100 public:
00104 XMLWriterBase() {
00105 m_InputObject = 0;
00106 }
00108 itkSetStringMacro(Filename);
00110 itkGetStringMacro(Filename);
00112 virtual int CanWriteFile(const char* name) = 0;
00114 void SetObject(T *toWrite) { m_InputObject = toWrite; }
00116 virtual int WriteFile() = 0;
00118 void WriteStartElement(const char *const tag,std::ofstream &file)
00119 {
00120 file << '<' << tag << '>';
00121 }
00123 void WriteEndElement(const char *const tag,std::ofstream &file)
00124 {
00125 file << '<' << '/' << tag << '>';
00126 }
00128 void WriteCharacterData(const char *const data,std::ofstream &file)
00129 {
00130 file << data;
00131 }
00133 void WriteStartElement(std::string &tag,std::ofstream &file)
00134 {
00135 WriteStartElement(tag.c_str(),file);
00136 }
00138 void WriteEndElement(std::string &tag,std::ofstream &file)
00139 {
00140 WriteEndElement(tag.c_str(),file);
00141 }
00143 void WriteCharacterData(std::string &data,std::ofstream &file)
00144 {
00145 WriteCharacterData(data.c_str(),file);
00146 }
00147 protected:
00148 T *m_InputObject;
00149 std::string m_Filename;
00150 };
00151
00152 }
00153 #endif