您的位置:首页 > 其它

使用tinyxml实现GetElementById函数

2016-09-01 00:00 10 查看
bool GetElementById(TiXmlElement* pRootEle,std::string &id,TiXmlElement* &Node)
{

TiXmlAttribute* attributeNode = NULL;

attributeNode = pRootEle->FirstAttribute();
while ( attributeNode )
{
std::string str = attributeNode->Name();
std::string strvalue = attributeNode->Value();
str = strlwr((char *)str.c_str());
if(strcmp(str.c_str(), "id") == 0 && strcmp(id.c_str(),strvalue.c_str()) == 0)
{
Node = pRootEle;
return true;
}
attributeNode = attributeNode->Next();
}

TiXmlElement* pEle = pRootEle;

for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement())
{
//递归处理子节点,获取节点指针
if(GetElementById(pEle,id,Node))
return true;
}

return false;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tinyxml