Begemoth's answer sounds very good to me.
Here is a simplified version of the TiXmlElement Accept () method that does not use a visitor and uses the TiXmlNode * parameter instead:
void TiXmlIterator::iterate(const TiXmlNode* el) { cout << "Iterating Node " << el->Value() << endl;
The Accept () method takes a TiXmlVisitor parameter as a parameter and does all iterations for you. And you do not need to call it on the whole document, but only the root node of the subtree that you want to go through. This way you can define specific behavior for subclasses of TiXmlNode by overriding the correct methods. Take a look at the implementation of TiXmlPrinter in the TinyXml source code for a good example of how this is done.
If you do not want to do this, here is another example:
bool MyTiXmlVisitor::Visit(const TiXmlText& text) { cout << "Visiting Text: " << text.Value() << endl; return true;
This will affect all text elements in the node subtree on which you call Accept (). To act on all elements, override the remaining TiXmlVisitor virtual methods. Then, in the code where you want to iterate over the subtree, follow these steps:
subtree_root_node->Accept( my_tixmlvisitor_object );
source share