如何在 TinyXML2 中迭代节点?我尝试按照文档进行操作,但无法掌握这一点。
http://www.grinninglizard.com/tinyxml2docs/index.html
我的 XML 已经加载到std::string
. 因此,以下编译:
#include "tinyxml2.hpp"
// assume I have code here which reads my XML into std::string sXML
tinyxml2::XMLDocument doc;
doc.Parse( sXML.c_str() );
现在我该怎么做doc
来迭代项目列表,以便我可以将里面的标题和作者字段提取到std::string
变量中?
这是我的 XML 示例:
<?xml version=“1.0” encoding=“utf-8”?>
<books>
<item>
<title>Letters to Gerhardt</title>
<author>Von Strudel, Jamath</author>
</item>
<item>
<title>Swiss Systemic Cleanliness Principles, The</title>
<author>Jöhansen, Jahnnes</author>
</item>
</books>
希望有一些简单的东西,比如 C++ vector
of item
,然后可能是 C++map
里面我可以通过"title"
and"author"
或.title
or来解决它.author
。