遞迴實現 根據元素屬性名稱,屬性值,返回對應的元素節點。詳情看代碼。
//遞迴所有節點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;} returnRecursionAllNode(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);}}