How does one iterate nodes in TinyXML2? I tried following the documentation but am not able to grasp this.
http://www.grinninglizard.com/tinyxml2docs/index.html
My XML is already loaded into std::string
. Thus, the following compiles:
#include "tinyxml2.hpp"
// assume I have code here which reads my XML into std::string sXML
tinyxml2::XMLDocument doc;
doc.Parse( sXML.c_str() );
Now what do I do with doc
to iterate the item list so that I can pull out the title and author fields inside into std::string
variables?
Here's my XML sample:
<?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>
Was hoping for something simple like a C++ vector
of item
and then perhaps a C++ map
inside where I can address it by "title"
and "author"
or .title
or .author
.
Note, I'm fairly new to C++. If you know of a way to optimize this in less lines, I'd be thrilled to see it.