提交 34732028 编写于 作者: 小代码2016's avatar 小代码2016

编辑节点

上级 260dc0e7
<?xml version="1.0" encoding="UTF-8"?>
<personList>
<person id="1001" name="khl001" age="34" manager="true">
<intro>这是一段介绍. 这是一段介绍.</intro>
</person>
<person id="1002" name="khl002" age="56" manager="false">
<intro>这是一段介绍. 这是一段介绍.</intro>
</person>
<person id="1003" name="khl003" age="48">
<intro>这是一段介绍. 这是一段介绍.</intro>
</person>
<person id="1004"/>
</personList>
......@@ -9,17 +9,28 @@
TEST_CASE("tinyxml2_edit_node")
{
std::string simpleXmlPath;
std::string xmlEditResultPath;
tinyxml2::XMLDocument doc;
tinyxml2::XMLError xmlError;
/**
* 查找节点
* 添加节点
*/
SUBCASE("add_node")
{
simpleXmlPath = getXmlPath("/data/simple.xml");
xmlEditResultPath = getXmlPath("/data/edit_result.xml");
xmlError = doc.LoadFile(simpleXmlPath.c_str());
CHECK(tinyxml2::XMLError::XML_SUCCESS == xmlError);
auto rootEl = doc.RootElement();
auto newPersonNode = doc.NewElement("person");
newPersonNode->SetAttribute("id","1004");
rootEl->InsertEndChild(newPersonNode);
doc.SaveFile(xmlEditResultPath.c_str());
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册