TinyXML 根据属性名,属性值返回对应的元素节点(源代码)

来源:互联网 发布:软件著作权多少钱 编辑:程序博客网 时间:2024/05/17 18:11

转载自: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);      }  }  


阅读全文
0 0
原创粉丝点击