pugi xml读与写接口
发布日期:2021-09-25 21:40:41
浏览次数:20
分类:技术文章
本文共 1089 字,大约阅读时间需要 3 分钟。
//写接口bool writeToXml(){ pugi::xml_document doc; if (m_path.empty()) { return false; } //根结点root pugi::xml_node root = doc.append_child("root"); pugi::xml_node info = root.append_child("info"); { assert(!info.child("info")); info.append_child("info").appen_attribute("msg").set_value("123"); } pugi::xml_node csv = root.append_child("csv"); { pugi::xml_node value = csv.append_child("var"); value.append_attribute("id").set_value("james"); value.append_attribute("comment").set_value("name"); } doc.save_file(m_path.c_str());}//读接口bool readFromXml(){ pugi::xml_document doc; if (m_path.empty() || !doc.load_file(m_path.c_str())) { return false; } pugi::xml_node root = doc.document_element(); for (pugi::xml_node node = root.child("info").first_child(); node; node = node.next_sibling()) { std::string info = node.attribute("msg").as_string(); //cl } for (pugi::xml_node node = root.child("csv").first_child(); node; node = node.next_sibling()) { std::string comment = node.attribute("comment").value(); std::string id = node.attribute("id").as_string(); //cl } return true;}
转载地址:https://blog.csdn.net/c_shell_python/article/details/105827860 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月18日 08时44分35秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【奇技淫巧】-- 三角形最小路径和
2019-04-27
【小技巧】argc和argv的用法
2019-04-27
学不下去了怎么办?
2019-04-27
二叉树的前中后序遍历(迭代法)(带动画)
2019-04-27
【小技巧】【XShell】【Xftp】Windows桌面与Linux虚拟机互传文件
2019-04-27
【redis入门】Centos下安装redis
2019-04-27
【redis入门】redis安装后相关知识串讲
2019-04-27
【redis】来吧,展示一下redis 发布-订阅模式
2019-04-27
当下热点词再学:redis缓存预热、更新、降级,限流
2019-04-27
【redis6.0.6】redis源码慢慢学,慢慢看 -- 第五天:adlist
2019-04-27
别抖,OK? 操作系统抖动现象、网络抖动与延迟、函数抖动之防抖与节流,串讲
2019-04-27
通过域名获取主机IP -- struct addrinfo
2019-04-27
【C++】算法集锦(8):从两数和问题拓展到一百数和问题
2019-04-27
【C++】算法集锦(9):背包问题
2019-04-27
【C++】算法集锦(10)通俗讲kmp算法
2019-04-27
【C++】算法集锦(12):高楼扔鸡蛋
2019-04-27
【图解】拥塞控制
2019-04-27