00001 /*************************************************************************** 00002 StrX.h - description 00003 ------------------- 00004 begin : Tue Oct 23 2001 00005 copyright : See Xerces C++ documentation 00006 email : case@ucdhep.ucdavis.edu 00007 ***************************************************************************/ 00008 00009 #ifndef STRX_H 00010 #define STRX_H 00011 00012 #include <xercesc/util/PlatformUtils.hpp> 00013 #include <xercesc/sax2/XMLReaderFactory.hpp> 00014 #include <xercesc/sax2/SAX2XMLReader.hpp> 00015 #include <xercesc/util/XMLString.hpp> 00016 #include <string> 00017 #include <iostream> 00018 00027 // --------------------------------------------------------------------------- 00028 // This is a simple class that lets us do easy (though not terribly efficient) 00029 // trancoding of XMLCh data to local code page for display. 00030 // --------------------------------------------------------------------------- 00031 class StrX 00032 { 00033 public: 00034 typedef xercesc_2_7::XMLString XMLString; 00035 // ----------------------------------------------------------------------- 00036 // Constructors and Destructor 00037 // ----------------------------------------------------------------------- 00038 StrX(const XMLCh* const toTranscode)// : fXMLChForm(toTranscode) 00039 { 00040 fLocalForm = XMLString::transcode(toTranscode); 00041 fXMLChForm = XMLString::transcode(fLocalForm); 00042 } 00043 00044 StrX( const char* const toTranscode ) 00045 { 00046 fXMLChForm = XMLString::transcode(toTranscode); 00047 fLocalForm = XMLString::transcode(fXMLChForm); 00048 } 00049 00050 StrX( const std::string& toTranscode ) 00051 { 00052 fXMLChForm = XMLString::transcode(toTranscode.c_str()); 00053 fLocalForm = XMLString::transcode(fXMLChForm); 00054 } 00055 00056 ~StrX() 00057 { 00058 XMLString::release(&fLocalForm); 00059 XMLString::release(&fXMLChForm); 00060 } 00061 00062 // ----------------------------------------------------------------------- 00063 // Getter methods 00064 // ----------------------------------------------------------------------- 00065 const char* localForm() const 00066 { 00067 return fLocalForm; 00068 } 00069 00070 const XMLCh* xmlChForm() const 00071 { 00072 return fXMLChForm; 00073 } 00074 00075 private: 00076 XMLCh * fXMLChForm; 00077 char * fLocalForm; 00078 00079 }; 00080 00081 inline std::ostream& operator<<(std::ostream& target, const StrX& toDump) 00082 { 00083 target << toDump.localForm(); 00084 return target; 00085 } 00086 #endif