使用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;
}
{
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;
}
相关文章推荐
- 使用临界段实现优化的进程间同步对象-原理和实现
- 使用MFC快速实现网络编程 CAsyncSocket
- 使用纯资源DLL文件实现多语言菜单、界面文字、Tooltips等
- 使用虚列表和自画实现文件夹的缩略图显示
- 实现Interface的方法不能使用static修饰符
- VSS实现版本控制管理的一些使用方法
- 应用WSDK-实现和使用DIME的Web Services(上)
- 借助VMware实现单机使用WinDbg
- 使用SQLSERVER的扩展存储过程实现远程备份与恢复
- 使用临界段原理实现优化的进程间同步对象-原理和实现
- 使用IPicture的OLE实现读取和显示BMP,GIF,JPG,ICO,EMF,WMF图像
- 使用Log4j为项目配置日志输出应用详解以及示例演示的实现分析
- 使用反射在NET中实现动态工厂(第一部分)
- C语言使用openSSL库DES模块实现加密功能详解
- 使用XML实现BBS(主题列表篇)
- 使用Java实现数据报通讯过程
- 使用VC6.0实现窗口的任意分割
- 应用WSDK-实现和使用DIME的Web Services(下)
- 使用PHP4中的 IntegratedTemplate类实现HTML和PHP代码分离
- 使用.NET实现断点续传(HTTP)