1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include "tinyxml.h"
//
// This file demonstrates some basic functionality of TinyXml.
// Note that the example is very contrived. It presumes you know
// what is in the XML file. But it does test the basic operations,
// and show how to add and remove nodes.
//
int level = 0;
char *getIndent(void)
{
static char buf[128];
int i;
for( i=0; i<level; i++)
{
buf[i] = ' ';
}
buf[i] = '\0';
return buf;
}
void TraverseMenu( TiXmlNode* child)
{
while( child)
{
fprintf( stdout, "%s[%s] : ", getIndent(), child->Value().c_str());
TiXmlElement* thisEntry = child->ToElement();
if( thisEntry)
{
TiXmlAttribute* attrib;
for ( attrib = thisEntry->FirstAttribute(); attrib; attrib = attrib->Next() )
{
fprintf( stdout, "[%s=%s] ", attrib->Name().c_str(), attrib->Value().c_str());
}
}
fprintf( stdout, "\n");
level++;
TraverseMenu( child->FirstChild());
level--;
child = child->NextSibling();
}
}
int main()
{
TiXmlDocument doc( "menu.xml" );
doc.LoadFile();
TraverseMenu( doc.FirstChild("Menu"));
return 0;
}
|