#include <iostream>
#include <string>
#include "tinyxml.h"
#define TIXML_USE_STL
using namespace std;
void ParaseUpdateXml(TiXmlNode* pParent);
int main()
{
TiXmlDocument doc("abc.xml");
doc.LoadFile();
TiXmlElement* root = doc.RootElement();
if(!root) return 1;
ParaseUpdateXml(root);
return 0;
}
void ParaseUpdateXml(TiXmlNode* pParent)
{
if(pParent == NULL)
return;
TiXmlNode* pchild = pParent->FirstChild();
while(pchild)
{
cout << pchild->Value() << " ";
int t = pchild->Type();
if( t == TiXmlNode::ELEMENT)
{
TiXmlAttribute* attr = pchild->ToElement()->FirstAttribute();
if(attr)
{
TiXmlNode* node = pchild;
while(node)
{
while(attr)
{
cout << " " << attr->Name() << "=" << attr->Value();
attr = attr->Next();
}
cout << endl;
node = node->NextSiblingElement();
}
}
ParaseUpdateXml(pchild);
}
else if( t == TiXmlNode::TEXT)
{
cout << pchild->Value() << endl;
}
pchild = pchild->NextSibling();
}
}