00001 // rdXMLDocument.h 00002 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00003 // Copyright 2002 Realistic Dynamics, Inc. 00004 // All rights reserved. 00005 // 00006 // Please do not read, copy, distribute, or use without permission. 00007 // Contact: Frank C. Anderson, fca@RealisticDynamics.com 00008 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00009 #ifndef __rdXMLDocument_h__ 00010 #define __rdXMLDocument_h__ 00011 00012 00013 // INCLUDES 00014 #include <iostream.h> 00015 #include <xercesc/idom/IDOM.hpp> 00016 #include <xercesc/parsers/IDOMParser.hpp> 00017 #include <xercesc/framework/XMLFormatter.hpp> 00018 #include "rdTools.h" 00019 00020 00021 // CLASS MEMBER TYPES 00022 class IDOMPrintFormatTarget; 00023 00024 00025 //============================================================================= 00026 //============================================================================= 00038 class RDTOOLS_API rdXMLDocument { 00039 00040 //============================================================================= 00041 // DATA 00042 //============================================================================= 00043 public: 00044 static const XMLCh UTF8[]; 00045 00046 private: 00048 IDOMParser *_parser; 00050 IDOM_Document *_document; 00051 00052 //============================================================================= 00053 // METHODS 00054 //============================================================================= 00055 //-------------------------------------------------------------------------- 00056 // CONSTRUCTION AND DESTRUCTION 00057 //-------------------------------------------------------------------------- 00058 public: 00059 virtual ~rdXMLDocument(); 00060 rdXMLDocument(); 00061 rdXMLDocument(const char *aFileName); 00062 rdXMLDocument(const rdXMLDocument &aDocument); 00063 private: 00064 void setNull(); 00065 00066 public: 00067 //-------------------------------------------------------------------------- 00068 // SET AND GET 00069 //-------------------------------------------------------------------------- 00070 IDOM_Document* getIDOMDocument() const; 00071 00072 //-------------------------------------------------------------------------- 00073 // IO 00074 //-------------------------------------------------------------------------- 00075 void print(const char *aFileName=NULL); 00076 private: 00077 static void CreateFormatter(ostream *aOstream=&cout); 00078 void printDeclaration(); 00079 00080 //============================================================================= 00081 }; // END CLASS rdXMLDocument 00082 //============================================================================= 00083 //============================================================================= 00084 00085 00086 00087 // --------------------------------------------------------------------------- 00088 // Local classes 00089 // --------------------------------------------------------------------------- 00090 00091 class IDOMPrintFormatTarget : public XMLFormatTarget 00092 { 00093 ostream *_out; 00094 public: 00095 IDOMPrintFormatTarget(ostream *aOStream= &cout) { 00096 _out = aOStream; 00097 }; 00098 ~IDOMPrintFormatTarget() {}; 00099 00100 // ----------------------------------------------------------------------- 00101 // Implementations of the format target interface 00102 // ----------------------------------------------------------------------- 00103 00104 void writeChars(const XMLByte* const toWrite, 00105 const unsigned int count, 00106 XMLFormatter * const formatter) 00107 { 00108 // Surprisingly, Solaris was the only platform on which 00109 // required the char* cast to print out the string correctly. 00110 // Without the cast, it was printing the pointer value in hex. 00111 // Quite annoying, considering every other platform printed 00112 // the string with the explicit cast to char* below. 00113 _out->write((char *) toWrite, (int) count); 00114 }; 00115 00116 private: 00117 // ----------------------------------------------------------------------- 00118 // Unimplemented methods. 00119 // ----------------------------------------------------------------------- 00120 IDOMPrintFormatTarget(const IDOMPrintFormatTarget& other); 00121 void operator=(const IDOMPrintFormatTarget& rhs); 00122 }; 00123 00124 00125 #endif // __rdXMLDocument_h__
1.3