Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Begemoth's answer sounds pretty good to me. </p> <p>Here is a simplified version of TiXmlElement's Accept() method, that doesn't use a visitor and instead takes a TiXmlNode* as the parameter:</p> <pre><code>void TiXmlIterator::iterate(const TiXmlNode* el) { cout &lt;&lt; "Iterating Node " &lt;&lt; el-&gt;Value() &lt;&lt; endl; // More useful code here... for (const TiXmlNode* node=el-&gt;FirstChild(); node; node=node-&gt;NextSibling()) { iterate(node); } // And/Or here. } </code></pre> <p>The Accept() method takes a TiXmlVisitor as a parameter and does all the iterating for you, though. And you don't have to call it on the whole document, just the root node of the subtree you want to traverse. This way, you can define specific behavior for the subclasses of TiXmlNode, by overriding the right methods. Look at the implementation of TiXmlPrinter in <a href="http://sourceforge.net/projects/tinyxml/" rel="nofollow">TinyXml's source code</a> for a good example of how it's done.</p> <p>In case you don't want to do that, here is another example:</p> <pre><code>bool MyTiXmlVisitor::Visit(const TiXmlText&amp; text) { cout &lt;&lt; "Visiting Text: " &lt;&lt; text.Value() &lt;&lt; endl; return true; // This will ensure it keeps iterating } </code></pre> <p>This will act on all text elements in the subtree of the node you call Accept() on. To act on <em>all</em> the elements, override the remaining virtual methods of TiXmlVisitor. Then, in the code where you want to iterate over the subtree, do the following:</p> <pre><code>subtree_root_node-&gt;Accept( my_tixmlvisitor_object ); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload