如何用tinyxml 库创建并读写xml代码截取
发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,本篇文章给大家分享的是有关如何用tinyxml 库创建并读写xml代码截取,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。因为自己每次写完
千家信息网最后更新 2025年02月04日如何用tinyxml 库创建并读写xml代码截取
本篇文章给大家分享的是有关如何用tinyxml 库创建并读写xml代码截取,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
因为自己每次写完之后都忘记了 然后又要从别的地方学习再重新写 还不如记录再这里//创建 TiXmlDocument *pXmlDocument = new TiXmlDocument(m_strFilePath.c_str());// TiXmlDeclaration *pDeclaretion = new TiXmlDeclaration("1.0", "UTF-8","");//创建xml声明 pXmlDocument->LinkEndChild(pDeclaretion); TiXmlElement *pXmlElement = new TiXmlElement("Symbol"); pXmlDocument->LinkEndChild(pXmlElement); pXmlDocument->SaveFile(m_strFilePath.c_str());//读TiXmlDocument *pXmlDoc = new TiXmlDocument(); pXmlDoc->LoadFile(strFilePath.c_str()); TiXmlElement *pRootElement = pXmlDoc->RootElement(); if (pRootElement == NULL) { return; } // 第一个子节点 TiXmlElement *pSignNode = pRootElement->FirstChildElement("sign"); if (!pSignNode) { SAFE_DELETE(pSignNode); return; } while (pSignNode != NULL) { CMapSingleParameter *pMapSingleParameter = new CMapSingleParameter(); if (!pMapSingleParameter) { SAFE_DELETE(pMapSingleParameter); return ; } // text TCHAR tcharValue[MAX_PATH * 4] = {_T('\0')}; // name const CHAR *pszName = pSignNode->Attribute("name"); if (pszName != NULL) { CommonUtil::UTF8ToTCHAR(pszName,tcharValue); pMapSingleParameter->AppendParameter(_T("name"), tcharValue); } // height const CHAR *pszHeight = pSignNode->Attribute("height"); if (pszHeight != NULL) { CommonUtil::UTF8ToTCHAR(pszHeight,tcharValue); pMapSingleParameter->AppendParameter(_T("height"), tcharValue); } //Content const CHAR *pszContent = pSignNode->GetText(); if (pszContent != NULL) { CommonUtil::UTF8ToTCHAR(pszContent,tcharValue); pMapSingleParameter->AppendParameter(_T("content"), tcharValue); } m_pLatelyVectorSymbol->push_back(pMapSingleParameter); pSignNode = pSignNode->NextSiblingElement(); } //写string strFile = m_strFilePath; //创建文档对象 TiXmlDocument myXmlDocument; //加载文件数据 myXmlDocument.LoadFile(strFile.c_str()); TiXmlElement *pRootElement = myXmlDocument.RootElement(); if (pRootElement == NULL) { return ; } if (pRootElement != NULL) { TiXmlElement *pFirstNode = pRootElement->FirstChildElement("sign"); if (pFirstNode == NULL) { int nSignPos = 0; for (TVectorSymbol::iterator ite = m_pLatelyVectorSymbol->begin(); ite != m_pLatelyVectorSymbol->end(); ++ite) { CMapSingleParameter *pMapSingleParameter = *ite; TiXmlElement *insertElement = new TiXmlElement("sign"); pRootElement->LinkEndChild(insertElement); xstring strUnicode = pMapSingleParameter->GetParameterValue(_T("name")); TCHAR tcharValue[MAX_PATH*4]= {_T('\0')}; _tcscpy(tcharValue, strUnicode.c_str()); char chUtf8[MAX_PATH*4] = {'\0'}; CommonUtil::TCHARToUTF8(tcharValue, chUtf8); insertElement->SetAttribute("name",chUtf8); strUnicode = pMapSingleParameter->GetParameterValue(_T("height")); _tcscpy(tcharValue, strUnicode.c_str()); CommonUtil::TCHARToUTF8(tcharValue, chUtf8); insertElement->SetAttribute("height",chUtf8); strUnicode = pMapSingleParameter->GetParameterValue(_T("content")); _tcscpy(tcharValue, strUnicode.c_str()); CommonUtil::TCHARToUTF8(tcharValue, chUtf8); TiXmlText *pXmlText = new TiXmlText(chUtf8); pXmlText->SetCDATA(true);//添加格式化 insertElement->LinkEndChild(pXmlText); m_nLatelyTotal ++; } } } myXmlDocument.SaveFile(strFile.c_str());}//删除节点 string strFile = m_strFilePath; //创建文档对象 TiXmlDocument myXmlDocument; //加载文件数据 myXmlDocument.LoadFile(strFile.c_str()); TiXmlElement *pRootElement = myXmlDocument.RootElement(); if (pRootElement == NULL) { return ; } TiXmlElement *pSignNode = pRootElement->FirstChildElement("sign"); while (pSignNode != NULL) { m_nLatelyTotal --; TiXmlElement *pSignRemoveNode = pSignNode; pSignNode= pSignNode->NextSiblingElement("sign"); pRootElement->RemoveChild(pSignRemoveNode); } myXmlDocument.SaveFile(strFile.c_str());
以上就是如何用tinyxml 库创建并读写xml代码截取,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。
代码
对象
数据
文件
文档
更多
知识
篇文章
节点
学习
实用
个子
地方
就是
工作会
文章
格式
看吧
知识点
行业
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
阿里云代理服务器地址
计算机网络技术 -吧
电厂一般使用什么数据库
山东网络安全应急预案
语音对讲软件开发优势
维护网络安全的话
服务器报b0
网络安全定级备案工作进展
数据库元分类
数据库 访问 中间件
河源软件开发的地方
英国兰卡斯特大学网络安全排名
CMD关闭数据库端口命令
艾莫讯串口服务器485转以太网
安全团队数据库审计
旭日宝宝斗鱼首播服务器炸了
校园网络安全手抄报简单易画
天盾服务器数据恢复软件
嘉兴映翰通网络技术有限公司宿舍
数据库事务指令的四个特性
计算机网络技术 -吧
云虚拟主机如何清除数据库
软件开发工具公司有哪些
网络技术基础知识考试题库
使用数据库需要建立服务器吗
数据库int怎么写
福田下沙java软件开发
中学生网络安全教案教案大全
北外网络技术中心
服务器软件是干什么的