2012-03-01 19 views
5

Myślę, że problem polega na niewłaściwym użyciu funkcji lub czegoś innego.Jak liczyć elementy w TinyXml?

Ta część kodu działa, ale wynik nie jest dobry.

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

Wynik count jest 1.


plik XML:

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

Nie można znaleźć przykładowe pracy.

+0

Co "nie jest dobrze" na temat wyniku? Jaki masz wynik i jakiego wyniku oczekujesz? –

+0

Następnie albo usuń pytanie, albo opublikuj rozwiązanie jako odpowiedź. –

+0

Rozwiązałem: pierwszy wiersz 'TiXmlElement * e = hDoc.FirstChildElement(). FirstChildElement(). Element();' get count of Max

Odpowiedz

9

Jeśli czytasz documentation można znaleźć następujący przykład (co wydaje neater niż podejścia):

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

Ale są chyba tylko próbuje policzyć stany więc proponuję:

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

prawdopodobnie też chce coś takiego:

TiXmlElement *parent = hDoc.RootElement(); 
Powiązane problemy