Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小代码2016
tinyxml2-study
提交
19e7aab8
tinyxml2-study
项目概览
小代码2016
/
tinyxml2-study
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
tinyxml2-study
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
19e7aab8
编写于
2月 02, 2023
作者:
小代码2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tinyxml2 基本使用
上级
cdbc74f5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
152 addition
and
3 deletion
+152
-3
data/edit_add_node_result.xml
data/edit_add_node_result.xml
+0
-0
data/edit_remove_node_result.xml
data/edit_remove_node_result.xml
+9
-0
one.xml
one.xml
+18
-0
test/test_tinyxml2_edit_node.cpp
test/test_tinyxml2_edit_node.cpp
+71
-2
test/test_tinyxml2_find_node.cpp
test/test_tinyxml2_find_node.cpp
+3
-1
test/test_tinyxml2_output.cpp
test/test_tinyxml2_output.cpp
+51
-0
未找到文件。
data/edit_result.xml
→
data/edit_
add_node_
result.xml
浏览文件 @
19e7aab8
文件已移动
data/edit_remove_node_result.xml
0 → 100644
浏览文件 @
19e7aab8
<?xml version="1.0" encoding="UTF-8"?>
<personList>
<person
id=
"1001"
name=
"khl001"
age=
"34"
manager=
"true"
>
<intro>
这是一段介绍. 这是一段介绍.
</intro>
</person>
<person
id=
"1003"
name=
"khl003"
age=
"48"
>
<intro>
这是一段介绍. 这是一段介绍.
</intro>
</person>
</personList>
one.xml
0 → 100644
浏览文件 @
19e7aab8
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite
name=
".\bin\Release\khl_xml_test"
errors=
"0"
failures=
"0"
tests=
"21"
time=
"0.02751"
timestamp=
"2023-02-01T19:48:40Z"
doctest_version=
"2.4.9"
>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_edit_node.cpp"
name=
"tinyxml2_edit_node/add_node"
time=
"0.010682"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_edit_node.cpp"
name=
"tinyxml2_edit_node/remove_node"
time=
"0.008068"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_find_node.cpp"
name=
"tinyxml2_find_node/find_node"
time=
"0.000273"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_load.cpp"
name=
"tinyxml2_load/load_by_path"
time=
"0.000182"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_load.cpp"
name=
"tinyxml2_load/load_by_path_file_not_found"
time=
"0.000147"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_load.cpp"
name=
"tinyxml2_load/load_by_file"
time=
"0.000196"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_load.cpp"
name=
"tinyxml2_load/load_by_charbuffe"
time=
"0"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_load.cpp"
name=
"tinyxml2_load/load_by_charbuffe"
time=
"0"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_output.cpp"
name=
"tinyxml2_output/add_node"
time=
"0.004744"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\test_tinyxml2_output.cpp"
name=
"tinyxml2_output/remove_node"
time=
"0.002015"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\testmain.cpp"
name=
"test 001"
time=
"0.000314"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\testmain.cpp"
name=
"test 003"
time=
"0.00062"
status=
"run"
/>
<testcase
classname=
"F:\2023\blog_code\tinyxml2-study\test\tmp_test.cpp"
name=
"test_tmp"
time=
"0.000269"
status=
"run"
/>
</testsuite>
</testsuites>
test/test_tinyxml2_edit_node.cpp
浏览文件 @
19e7aab8
...
...
@@ -20,17 +20,86 @@ TEST_CASE("tinyxml2_edit_node")
SUBCASE
(
"add_node"
)
{
simpleXmlPath
=
getXmlPath
(
"/data/simple.xml"
);
xmlEditResultPath
=
getXmlPath
(
"/data/edit_result.xml"
);
xmlEditResultPath
=
getXmlPath
(
"/data/edit_
add_node_
result.xml"
);
xmlError
=
doc
.
LoadFile
(
simpleXmlPath
.
c_str
());
CHECK
(
tinyxml2
::
XMLError
::
XML_SUCCESS
==
xmlError
);
auto
rootEl
=
doc
.
RootElement
();
const
char
*
id
=
"1004"
;
auto
newPersonNode
=
doc
.
NewElement
(
"person"
);
newPersonNode
->
SetAttribute
(
"id"
,
"1004"
);
newPersonNode
->
SetAttribute
(
"id"
,
id
);
rootEl
->
InsertEndChild
(
newPersonNode
);
doc
.
SaveFile
(
xmlEditResultPath
.
c_str
());
xmlError
=
doc
.
LoadFile
(
xmlEditResultPath
.
c_str
());
CHECK
(
tinyxml2
::
XMLError
::
XML_SUCCESS
==
xmlError
);
rootEl
=
doc
.
RootElement
();
auto
personNode
=
rootEl
->
FirstChildElement
(
"person"
);
while
(
nullptr
!=
personNode
)
{
if
(
0
==
strcmp
(
id
,
personNode
->
Attribute
(
"id"
)))
{
break
;
}
personNode
=
personNode
->
NextSiblingElement
();
}
bool
hasNewPersonNode
=
nullptr
!=
personNode
;
CHECK
(
hasNewPersonNode
);
}
/**
* 删除节点
*/
SUBCASE
(
"remove_node"
)
{
simpleXmlPath
=
getXmlPath
(
"/data/simple.xml"
);
xmlEditResultPath
=
getXmlPath
(
"/data/edit_remove_node_result.xml"
);
xmlError
=
doc
.
LoadFile
(
simpleXmlPath
.
c_str
());
CHECK
(
tinyxml2
::
XMLError
::
XML_SUCCESS
==
xmlError
);
const
char
*
id
=
"1002"
;
auto
rootEl
=
doc
.
RootElement
();
auto
personNode
=
rootEl
->
FirstChildElement
(
"person"
);
while
(
nullptr
!=
personNode
)
{
if
(
0
==
strcmp
(
id
,
personNode
->
Attribute
(
"id"
)))
{
break
;
}
personNode
=
personNode
->
NextSiblingElement
();
}
rootEl
->
DeleteChild
(
personNode
);
doc
.
SaveFile
(
xmlEditResultPath
.
c_str
());
xmlError
=
doc
.
LoadFile
(
xmlEditResultPath
.
c_str
());
CHECK
(
tinyxml2
::
XMLError
::
XML_SUCCESS
==
xmlError
);
rootEl
=
doc
.
RootElement
();
personNode
=
rootEl
->
FirstChildElement
(
"person"
);
while
(
nullptr
!=
personNode
)
{
if
(
0
==
strcmp
(
id
,
personNode
->
Attribute
(
"id"
)))
{
break
;
}
personNode
=
personNode
->
NextSiblingElement
();
}
bool
person1002NotExist
=
nullptr
==
personNode
;
CHECK
(
person1002NotExist
);
}
}
\ No newline at end of file
test/test_tinyxml2_find_node.cpp
浏览文件 @
19e7aab8
...
...
@@ -28,7 +28,7 @@ TEST_CASE("tinyxml2_find_node")
auto
personNode
=
rootEl
->
FirstChildElement
(
"person"
);
while
(
nullptr
!=
personNode
)
{
if
(
strcmp
(
id
,
personNode
->
Attribute
(
"id"
)))
if
(
0
==
strcmp
(
id
,
personNode
->
Attribute
(
"id"
)))
{
break
;
}
...
...
@@ -38,5 +38,7 @@ TEST_CASE("tinyxml2_find_node")
bool
find
=
nullptr
!=
personNode
;
CHECK
(
find
);
bool
idCheck
=
0
==
strcmp
(
id
,
personNode
->
Attribute
(
"id"
));
CHECK
(
idCheck
);
}
}
\ No newline at end of file
test/test_tinyxml2_output.cpp
0 → 100644
浏览文件 @
19e7aab8
#include <cstdio>
#include <cstring>
#include "doctest/doctest.h"
#include "tinyxml2.h"
#include "spdlog/spdlog.h"
#include "khl_xml_config/khl_xml_config.hpp"
TEST_CASE
(
"tinyxml2_output"
)
{
std
::
string
simpleXmlPath
;
std
::
string
xmlEditResultPath
;
tinyxml2
::
XMLDocument
doc
;
tinyxml2
::
XMLError
xmlError
;
/**
* 添加节点
*/
SUBCASE
(
"add_node"
)
{
simpleXmlPath
=
getXmlPath
(
"/data/simple.xml"
);
xmlEditResultPath
=
getXmlPath
(
"/data/edit_add_node_result.xml"
);
xmlError
=
doc
.
LoadFile
(
simpleXmlPath
.
c_str
());
CHECK
(
tinyxml2
::
XMLError
::
XML_SUCCESS
==
xmlError
);
doc
.
Print
();
}
/**
* 删除节点
*/
SUBCASE
(
"remove_node"
)
{
simpleXmlPath
=
getXmlPath
(
"/data/simple.xml"
);
xmlEditResultPath
=
getXmlPath
(
"/data/edit_remove_node_result.xml"
);
xmlError
=
doc
.
LoadFile
(
simpleXmlPath
.
c_str
());
CHECK
(
tinyxml2
::
XMLError
::
XML_SUCCESS
==
xmlError
);
tinyxml2
::
XMLPrinter
printer
;
doc
.
Print
(
&
printer
);
spdlog
::
info
(
"xml content:
\n
{}"
,
printer
.
CStr
());
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录