转载自:http://blog.csdn.net/wojiushi3344/article/details/7925932
//递归所有节点
TiXmlElement* RecursionAllNode(TiXmlElement * pElement,string attributName,string attributValue)
{
string strValue;
TiXmlElement* retValue;
if (pElement== NULL)
{
return NULL;
}else if (pElement->NoChildren())
{
pElement->QueryValueAttribute(attributName,&strValue);
if (attributValue==strValue)
{
return pElement;
}
return RecursionAllNode(NULL,attributName,attributValue);
}else if (!pElement->NoChildren())
{
pElement->QueryValueAttribute(attributName,&strValue);
if (attributValue==strValue)
{
cout<<pElement->Value()<<endl;
return pElement;
}
TiXmlElement * pChilds = pElement->FirstChildElement();//第一个子结点
retValue=RecursionAllNode(pChilds,attributName,attributValue);
if (retValue!=NULL)
{
return retValue;
}
//递归子结点
pChilds = pChilds->NextSiblingElement();
while ( NULL != pChilds )//递归处理此结点下的所有结点
{
retValue=RecursionAllNode(pChilds,attributName,attributValue);
if (retValue!=NULL)
{
return retValue;
}
pChilds = pChilds->NextSiblingElement();
}
return RecursionAllNode(NULL,attributName,attributValue);
}
}