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