void walkScript(TiXmlElement* element) { TiXmlElement* child = 0; for( child = element->FirstChildElement(); child; child = child->NextSiblingElement() ) { string tag = child->Value(); printf("%s\n",child->Value()); walkScript(child->ToElement()); } }
Hi i have a function that looks something like this to walk all nodes. But i need to know how deep i am, like this:
<tag> depth 0 <tag> depth 1 <tag></tag> depth 2 </tag> depth 1 </tag> depth 0
Thanks In Advance
/Fredrik
Why not do the standard recursive strategy of passing in a variable to walkScript?
like
void walkScript(TiXmlElement* element, int depth=0) { TiXmlElement* child = 0; for( child = element->FirstChildElement(); child; child = child->NextSiblingElement() ) { string tag = child->Value(); printf("%s Depth %d\n",child->Value(), depth); walkScript(child->ToElement(), depth+1); } }
?
Thank you! Don't know what i was thinking ; )
No worries. We all have those moments :)
Log in to post a comment.
void walkScript(TiXmlElement* element)
{
TiXmlElement* child = 0;
for( child = element->FirstChildElement(); child; child = child->NextSiblingElement() )
{
string tag = child->Value();
printf("%s\n",child->Value());
walkScript(child->ToElement());
}
}
Hi i have a function that looks something like this to walk all nodes.
But i need to know how deep i am, like this:
<tag> depth 0
<tag> depth 1
<tag></tag> depth 2
</tag> depth 1
</tag> depth 0
Thanks In Advance
/Fredrik
Why not do the standard recursive strategy of passing in a variable to walkScript?
like
void walkScript(TiXmlElement* element, int depth=0)
{
TiXmlElement* child = 0;
for( child = element->FirstChildElement(); child; child = child->NextSiblingElement() )
{
string tag = child->Value();
printf("%s Depth %d\n",child->Value(), depth);
walkScript(child->ToElement(), depth+1);
}
}
?
Thank you!
Don't know what i was thinking ; )
No worries.
We all have those moments :)