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);
}
}
//递归所有节点
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);
}
}
相关文章推荐
- TinyXML 根据属性名,属性值返回对应的元素节点(源代码)
- JQuery中根据属性或属性值获得元素(6种情况获取方法)
- jquery 根据属性或属性值获取元素的 6 种方法
- JQuery中根据属性或属性值获得元素(6种情况获取方法)
- JQuery中根据属性或属性值获得元素
- JQuery中根据属性或属性值获得元素
- JQuery中根据属性或属性值获得元素
- 4000 JQuery中根据属性或属性值获得元素
- JQuery中根据属性或属性值获得元素
- JQuery中根据属性或属性值获得元素(6种情况获取方法)
- JQuery中根据属性或属性值获得元素(6种情况获取方法)
- JQuery中6种根据属性或属性值获得元素获取方法
- 标签data-*自定义属性值和根据data属性值查找对应标签
- JQuery中根据属性或属性值获得元素
- JQuery中根据属性或属性值获得元素
- JQuery中根据属性或属性值获得元素(6种情况获取方法)
- JQuery中根据属性或属性值获得元素
- JQuery中根据属性或属性值获得元素(6种情况获取方法)
- JQuery中根据属性或属性值获得元素
- JQuery中根据属性或属性值获得元素