pugi xml读与写接口

//写接口
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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值