0

I am updating code that uses the legacy TinyXml library, to use new TinyXML-2 version instead.

While editing, I noticed that the function TiXmlNode::FirstChild(const char *) has no direct replacement in TinyXML-2.

My questions are:

  1. Is there a convenient replacement for the aforementioned function that I missed?
  2. In case there isn't, how should the example code below be updated for TinyXML-2?
// TiXmlElement *element; // assume this was correctly loaded
TiXmlNode *node;

if ((node = element->FirstChild("example")) != nullptr)
{
    for (TiXmlElement *walk = node->FirstChildElement();
        walk != nullptr;
        walk = walk->NextSiblingElement())
    {
        // ...
    }
}
user7023624
  • 571
  • 5
  • 14

1 Answers1

1

tinyxml2 has

const XMLElement * XMLNode::FirstChildElement (const char *value=0) const

Your code block is much the same:

if (auto example = element -> FirstChildElement ("example")
{
   for (auto walk = example -> FirstChildElement();
        walk;
        walk -> NextSiblingElement())
   {
   // walk the walk
   }
}

Or you might look at my add-on for tinyxml2 with which your snippet would be:

for (auto walk : selection (element, "example/")
{
   // walk the walk
}
stanthomas
  • 1,141
  • 10
  • 9