title: How do I write a generic C++ function to parse xml into structs?
body: <p>I have a collection of xml data files representing objects of interest in images (rectangles, points, labelled faces, etc.) that I want to parse to produce vectors of structs. The files are manually created (and so are not just the result of serialising some C++ objects) and are of the following form:</p>
  
  <pre><code>&lt;root&gt;
  &lt;image filename=whatever&gt;
  &lt;object&gt;
    &lt;x&gt;1&lt;/x&gt;
    &lt;y&gt;2&lt;/y&gt;
  &lt;/object&gt;
  &lt;object&gt;
    &lt;x&gt;3&lt;/x&gt;
    &lt;y&gt;4&lt;/y&gt;
  &lt;/object&gt;
  &lt;/image&gt;
  &lt;image filename=something&gt;
   ...
  &lt;/image&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>So a collection of images, each of which contains a collection of object children, each of which has children giving the data relevant to that object. The structure of this data varies between files, e.g. in one file each object might just have an x and a y and in another each object might contain ints x1, y1, x2, y2 and a double z.</p>
  
  <p>I want to parse such a file to produce a vector of Objects, where Object is a struct, in this case of the form struct Object { int x; int y; }.</p>
  
  <p>For different choices of Object, I've currently got separate functions that use rapidxml to parse the xml in identical ways, except for which fields they extract. </p>
  
  <p>I'd like to write a templated function so that you can merely specify the elements of a struct in some way and have the function return a vector of the appropriate structs. i.e. The user should specify a list of pairs ("x1", int), ("x2", int), etc. and have the rest of the work be done automatically.</p>
  
  <p>I'm sure there must be a nice boost solution to this problem that avoids having to use XML schema. How do I do this? </p>