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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Qt实现 可移动的无边框窗口
下一篇:Qt实现 MusicPlayer(本地)

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月18日 08时44分35秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章