   tinyxml parsing
  Hi,I got a pseudo-gpx file (it's xml):<?xml version="1.0" ?><gpx creator="CEA">    <trk>   <trkseg>  <trkpt lat="12.345" lon="1.234"> <time>2010-05-20T13:33:03</time> <ele>0085</ele> <course>000</course> <speed>5.556</speed> <fix>3</fix> <sat>05</sat> <pdop>.1</pdop> <hdop>.5</hdop> <vdop>.8</vdop> <temp>25</temp> <bat>3.27</bat> <ttff>15</ttff>  </trkpt>  <trkpt lat="12.345" lon="1.234"> <time>2010-05-20T13:33:14</time> <ele>0084</ele> <course>339</course> <speed>24.07</speed> <fix>3</fix> <sat>05</sat> <pdop>.1</pdop> <hdop>.5</hdop> <vdop>.8</vdop> <temp>25</temp> <bat>3.27</bat> <ttff>7</ttff>  </trkpt>...I would like to get all <ttff> fields. I'm using tinyxml. I know C++ but I'm coding xml since 2 days ;)I tryed different things but nothing works. Do you have any advice?Thanks   
  So you just want to find the "ttff" elements (and presumably their data), but that's it? If you're only looking for a particular element and don't care about its context, making a Visitor would be the easiest approach. Basically, you subclass TiXmlVisitor and give it a vector or something to hold the ttff datas, and have it check elements to see if they're named "ttff", and if so, you record their data in the vevtor. In your main code, you create one of your visitor objects, feed it to your XML document's Accept() method; it calls your Visitor with all the elements, with your visitor recording the ones it wants; afterwards, your visitor has all the ttff datas stored in it for you to take out.For an even easier solution, use TinyXPath or another XPath library and just use the query "//ttff/text()".   ;  I wrote a really simple template on top of TinyXml that you might find useful:#include <map>#include "tinyxml.h"#include "boost/function.hpp"template <class T> class XmlTraverser {protected:typedef boost::function<void(TiXmlNode*, T&)> NodeHandlerType;typedef std::map<std::string, NodeHandlerType> ElementHandlerMap;typedef std::map<int, NodeHandlerType> NodeHandlerMap;ElementHandlerMap _open_element_handlers;ElementHandlerMap _close_element_handlers;NodeHandlerMap _open_node_handlers;NodeHandlerMap _close_node_handlers;public:void registerOpenElementHandler(const std::string& element, NodeHandlerType handler) {_open_element_handlers[element] = handler;}void registerOpenNodeHandler(int typ, NodeHandlerType handler) {_open_node_handlers[typ] = handler;}void registerCloseElementHandler(const std::string& element, NodeHandlerType handler) {_close_element_handlers[element] = handler;}void registerCloseNodeHandler(int typ, NodeHandlerType handler) {_close_node_handlers[typ] = handler;}void callHandler(TiXmlNode* node, T& output, ElementHandlerMap& element_handlers, NodeHandlerMap& node_handlers) {int node_type = node->Type();if (node_type == TiXmlNode::ELEMENT) {std::string element_type = node->Value();if (element_handlers.find(element_type) != element_handlers.end()) {element_handlers[element_type](node, output);} } else {if (node_handlers.find(node_type) != node_handlers.end()) {node_handlers[node_type](node, output);}}}void run(TiXmlNode* node, T& output) {callHandler(node, output, _open_element_handlers, _open_node_handlers);for (TiXmlNode* child = node->FirstChild(); child != 0; child = child->NextSibling()) {run(child, output);}callHandler(node, output, _close_element_handlers, _close_node_handlers);}};Have a class inherit from the above, templated on whatever output type you want to be of doing the traversal and in the constructor of that class register handlers for the elements you are interested in like this:struct TrkptsStruct {   // or whatever you want the output to be   ...}class GpxTraverser : public XmlTraverser<TrkptsStruct> {protected:    void handleTrkpt(TiXmlNode* node, TrkptsStruct& output) {  ...    }public:    GpxTraverser() {   registerOpenElementHandler(  "trkpt",   boost::bind(&GpxTraverser::handleTrkpt, this, _1)   );    }};and then TrkptsStruct trkpts;GpxTraverser gpx_trav;TiXmlDocument doc(xml_file);if (! doc.LoadFile()) {   throw std::runtime_error("Invalid XML");}gpx_trav.run(&doc, trkpts);