00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef ENV_PARAM_PARAM_XML_PRINTER_H
00041 #define ENV_PARAM_PARAM_XML_PRINTER_H
00042
00043 namespace Onikiri
00044 {
00045 class ParamXMLPrinter : public TiXmlVisitor
00046 {
00047
00048 public:
00049
00050 ParamXMLPrinter()
00051 {
00052 m_simpleTextPrint = false;
00053 m_indetStr = " ";
00054 m_depth = 0;
00055 }
00056
00057 const char* CStr() const
00058 {
00059 return m_buffer.c_str();
00060 }
00061
00062 void IncDepth()
00063 {
00064 m_depth++;
00065 }
00066
00067 void DecDepth()
00068 {
00069 m_depth--;
00070 }
00071
00072 void Indent()
00073 {
00074 for( int i = 0; i < m_depth; i++ ){
00075 m_buffer += m_indetStr;
00076 }
00077 }
00078
00079 void LineBreak()
00080 {
00081 m_buffer += "\n";
00082 }
00083
00084 bool VisitEnter( const TiXmlDocument& )
00085 {
00086 return true;
00087 }
00088
00089 bool VisitExit( const TiXmlDocument& )
00090 {
00091 return true;
00092 }
00093
00094 bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute )
00095 {
00096 Indent();
00097 m_buffer += "<";
00098 m_buffer += element.Value();
00099 #if 0
00100 for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() ){
00101 m_buffer += " ";
00102 attrib->Print( 0, 0, &m_buffer );
00103 }
00104 #else
00105 IncDepth();
00106 for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() ){
00107 LineBreak();
00108 Indent();
00109 attrib->Print( 0, 0, &m_buffer );
00110 }
00111 DecDepth();
00112 if( firstAttribute ){
00113 LineBreak();
00114 Indent();
00115 }
00116 #endif
00117 if( !element.FirstChild() ){
00118 m_buffer += " />";
00119 LineBreak();
00120 }
00121 else{
00122 m_buffer += ">";
00123 if( element.FirstChild()->ToText() &&
00124 element.LastChild() == element.FirstChild() &&
00125 element.FirstChild()->ToText()->CDATA() == false
00126 ){
00127 m_simpleTextPrint = true;
00128 }
00129 else{
00130 LineBreak();
00131 }
00132 }
00133 IncDepth();
00134 return true;
00135 }
00136
00137
00138 bool VisitExit( const TiXmlElement& element )
00139 {
00140 DecDepth();
00141 if( !element.FirstChild() ){
00142
00143 }
00144 else{
00145 if( m_simpleTextPrint ){
00146 m_simpleTextPrint = false;
00147 }
00148 else{
00149 Indent();
00150 }
00151 m_buffer += "</";
00152 m_buffer += element.Value();
00153 m_buffer += ">";
00154 LineBreak();
00155 }
00156 return true;
00157 }
00158
00159
00160 bool Visit( const TiXmlText& text )
00161 {
00162 if( text.CDATA() ){
00163 Indent();
00164 m_buffer += "<![CDATA[";
00165 m_buffer += text.Value();
00166 m_buffer += "]]>";
00167 LineBreak();
00168 }
00169 else if( m_simpleTextPrint ){
00170
00171
00172
00173
00174 m_buffer += text.ValueTStr();
00175 }
00176 else{
00177 Indent();
00178 TIXML_STRING str;
00179 TiXmlBase::EncodeString( text.ValueTStr(), &str );
00180 m_buffer += str;
00181 LineBreak();
00182 }
00183 return true;
00184 }
00185
00186
00187 bool Visit( const TiXmlDeclaration& declaration )
00188 {
00189 Indent();
00190 declaration.Print( 0, 0, &m_buffer );
00191 LineBreak();
00192 return true;
00193 }
00194
00195
00196 bool Visit( const TiXmlComment& comment )
00197 {
00198 Indent();
00199 m_buffer += "<!--";
00200 m_buffer += comment.Value();
00201 m_buffer += "-->";
00202 LineBreak();
00203 return true;
00204 }
00205
00206
00207 bool Visit( const TiXmlUnknown& unknown )
00208 {
00209 Indent();
00210 m_buffer += "<";
00211 m_buffer += unknown.Value();
00212 m_buffer += ">";
00213 LineBreak();
00214 return true;
00215 }
00216
00217 protected:
00218 TIXML_STRING m_buffer;
00219 TIXML_STRING m_indetStr;
00220 int m_depth;
00221 bool m_simpleTextPrint;
00222
00223 };
00224 };
00225
00226 #endif
00227