So, in RapidXML, I'm trying to loop through my file to get the data from some tileset
nodes:
rapidxml::xml_node<> *root_node = doc.first_node("map");
for(rapidxml::xml_node<> *tileset = root_node->first_node("tileset");
tileset != 0; tileset = tileset->next_sibling("tileset"))
{
// Iteration stuff...
You're probably saying, what's the problem? Well, in RapidXML, the next_sibling()
function optionally matches the name:
xml_node<Ch>* next_sibling(const Ch *name=0, std::size_t name_size=0, bool
case_sensitive=true) const;
Gets next sibling node, optionally matching node name. Behaviour is undefined
if node has no parent. Use parent() to test if node has a parent.
Hence, if a node is not found with the name, it'll just return the next sibling regardless. This is a problem in my program, and I just plain don't want the extra iteration. I think this is stupid, but whatever. Is there a way to make it ONLY iterate through my tileset
nodes?
"optionally matching node name" - As in the parameter is optional. If you pass a name string, and it is not found you will get a return value of zero.
I also had this problem and I used this small modification as a workaround, which works as intended.