您的位置:首页 > 编程语言

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

2017-06-23 15:49 483 查看
转载自: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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: