Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count elements in TinyXml?

I think problem is with wrong using function or something else.

This part of code is working but the result isn't well.

TiXmlElement* e = hDoc.FirstChildElement().Element(); // think problem is there
while (e)
{
    e = e->NextSiblingElement();  //or may be there
    count++;
}

The result of count is 1.


Xml file is:

<doc>
   <state> ... </state>
   <state> ... </state>
   ...
</doc>

Can't find work example.

like image 504
Max Avatar asked Mar 01 '12 00:03

Max


1 Answers

if you read the documentation you can find the following example (which seems neater than your approach):

for( child = parent->FirstChild(); child; child = child->NextSibling() )
    count++;

But you are probably only trying to count the states so I would suggest:

for( child = parent->FirstChild("state"); child; child = child->NextSibling("state") )

You probably also want something like this:

TiXmlElement *parent = hDoc.RootElement();
like image 197
Underdetermined Avatar answered Sep 27 '22 23:09

Underdetermined