Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the child elements in tinyxml2

Tags:

c++

tinyxml2

This is probably a novice question, but I am new to tinyxml2 and can't find anything about this.

I am trying to loop through a XML file using tinyxml2.

<images>
    <correctImage>image1.png</correctImage>
    <image>image2.png</image>
    <image>image3.png</image>
</images>

I have the XMLElement of the image element, but I am not sure how to get the inside elements.

Any hand would be appreciated.

For the record, this is how I get the XML element:

tinyxml2::XMLElement *levelElement = doc.FirstChildElement("reactor")->FirstChildElement("level")->FirstChildElement("images");

Thanks in advance.

like image 665
EduAlm Avatar asked Mar 25 '13 02:03

EduAlm


1 Answers

You do it the same way you're doing it now, except you don't specify the value of the element you are looking for.

E.g.

tinyxml2::XMLElement *levelElement = doc.FirstChildElement("reactor")->FirstChildElement("level")->FirstChildElement("images");
for (tinyxml2::XMLElement* child = levelElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
{
    // do something with each child element
}
like image 62
Jonathan Potter Avatar answered Nov 10 '22 04:11

Jonathan Potter