Go to the documentation of this file.00001
00002
00003 #include "tinyxml.h"
00004
00005
00006
00007
00008 const unsigned int NUM_INDENTS_PER_SPACE=2;
00009
00010 const char * getIndent( unsigned int numIndents )
00011 {
00012 static const char * pINDENT=" + ";
00013 static const unsigned int LENGTH=strlen( pINDENT );
00014 unsigned int n=numIndents*NUM_INDENTS_PER_SPACE;
00015 if ( n > LENGTH ) n = LENGTH;
00016
00017 return &pINDENT[ LENGTH-n ];
00018 }
00019
00020
00021 const char * getIndentAlt( unsigned int numIndents )
00022 {
00023 static const char * pINDENT=" ";
00024 static const unsigned int LENGTH=strlen( pINDENT );
00025 unsigned int n=numIndents*NUM_INDENTS_PER_SPACE;
00026 if ( n > LENGTH ) n = LENGTH;
00027
00028 return &pINDENT[ LENGTH-n ];
00029 }
00030
00031 int dump_attribs_to_stdout(TiXmlElement* pElement, unsigned int indent)
00032 {
00033 if ( !pElement ) return 0;
00034
00035 TiXmlAttribute* pAttrib=pElement->FirstAttribute();
00036 int i=0;
00037 int ival;
00038 double dval;
00039 const char* pIndent=getIndent(indent);
00040 printf("\n");
00041 while (pAttrib)
00042 {
00043 printf( "%s%s: value=[%s]", pIndent, pAttrib->Name(), pAttrib->Value());
00044
00045 if (pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS) printf( " int=%d", ival);
00046 if (pAttrib->QueryDoubleValue(&dval)==TIXML_SUCCESS) printf( " d=%1.1f", dval);
00047 printf( "\n" );
00048 i++;
00049 pAttrib=pAttrib->Next();
00050 }
00051 return i;
00052 }
00053
00054 void dump_to_stdout( TiXmlNode* pParent, unsigned int indent = 0 )
00055 {
00056 if ( !pParent ) return;
00057
00058 TiXmlNode* pChild;
00059 TiXmlText* pText;
00060 int t = pParent->Type();
00061
00062 int num;
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 std::string pstring = pParent->Value();
00075
00076 size_t found=pstring.rfind("picture_high");
00077 if (found!=std::string::npos)
00078 {
00079 std::cerr << "First child: " << pParent->FirstChild()->Value() << std::endl;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
00115 {
00116 dump_to_stdout( pChild, indent+1 );
00117 }
00118 }
00119
00120
00121 void dump_to_stdout(const char* pFilename)
00122 {
00123 TiXmlDocument doc(pFilename);
00124 bool loadOkay = doc.LoadFile();
00125 if (loadOkay)
00126 {
00127 printf("\n%s:\n", pFilename);
00128 dump_to_stdout( &doc );
00129 }
00130 else
00131 {
00132 printf("Failed to load file \"%s\"\n", pFilename);
00133 }
00134 }
00135
00136
00137
00138
00139 int main(int argc, char* argv[])
00140 {
00141 for (int i=1; i<argc; i++)
00142 {
00143 dump_to_stdout(argv[i]);
00144 }
00145 return 0;
00146 }