title: Creating an XML file in OpenCV
body: <p>I have created an XML file, but when I try to read it in I get an error about a duplicate key. When I opened the XML file I noticed that nothing was nested and everything was treated as it's own individual node. I was wondering if there was a way to properly create the XML file and be able to parse through it as well. Below I have included my code for writing an XML file out, my XML output, and what I would like it to be.</p>
  
  <p>XML Code:</p>
  
  <pre><code>// Open up the file so that we can write to it
  cv::FileStorage fs;
  fs.open(szFileName, cv::FileStorage::WRITE);
  
  // Check if we actually created the file
  if(fs.isOpened())
  {
      fs &lt;&lt; "Total_Images" &lt;&lt; (int)vImages.size();
      //cv::write(fs, "Total Images", (int)vImages.size());
  
      for(int i = 0; i &lt; (int)vImages.size(); i++)
      {
          char szSize[8];
          string szNode;
          szNode = "image_";
          itoa(i, szSize, 10);
          szNode += szSize;
  
          fs &lt;&lt; "Node" &lt;&lt; szNode;
          fs &lt;&lt; "Width" &lt;&lt; vImages[i]-&gt;GetWidth();
          fs &lt;&lt; "Height" &lt;&lt; vImages[i]-&gt;GetHeight();
          fs &lt;&lt; "Keypoint_Size" &lt;&lt; (int)vImages[i]-&gt;GetKeyPoints().size();
  
          for(int j = 0; j &lt; vImages[i]-&gt;GetKeyPoints().size(); j++)
          {
              char szSize[256];
              fs &lt;&lt; "Angle" &lt;&lt; vImages[i]-&gt;GetKeyPoints()[j].angle;
              fs &lt;&lt; "Class" &lt;&lt; vImages[i]-&gt;GetKeyPoints()[j].class_id;
              fs &lt;&lt; "Octave" &lt;&lt; vImages[i]-&gt;GetKeyPoints()[j].octave;
              fs &lt;&lt; "Pt_X" &lt;&lt; vImages[i]-&gt;GetKeyPoints()[j].pt.x;
              fs &lt;&lt; "Pt_Y" &lt;&lt; vImages[i]-&gt;GetKeyPoints()[j].pt.y;
              fs &lt;&lt; "Response" &lt;&lt; vImages[i]-&gt;GetKeyPoints()[j].response;
              fs &lt;&lt; "Size" &lt;&lt; vImages[i]-&gt;GetKeyPoints()[j].size;
          }
  
          fs &lt;&lt; "Descriptors" &lt;&lt; vImages[i]-&gt;GetDescriptors();
      }
  
      fs.release();
  }
  </code></pre>
  
  <p>XML Output:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;opencv_storage&gt;
  &lt;Total_Images&gt;1&lt;/Total_Images&gt;
  &lt;Node&gt;image_0&lt;/Node&gt;
  &lt;Width&gt;500&lt;/Width&gt;
  &lt;Height&gt;266&lt;/Height&gt;
  &lt;Keypoint_Size&gt;268&lt;/Keypoint_Size&gt;
  &lt;Angle&gt;8.7332672119140625e+001&lt;/Angle&gt;
  &lt;Class&gt;0&lt;/Class&gt;
  &lt;Octave&gt;-1&lt;/Octave&gt;
  &lt;Pt_X&gt;1.7401049804687500e+002&lt;/Pt_X&gt;
  &lt;Pt_Y&gt;6.5084960937500000e+001&lt;/Pt_Y&gt;
  &lt;Response&gt;0.&lt;/Response&gt;
  &lt;Size&gt;1.1386331558227539e+001&lt;/Size&gt;
  &lt;Angle&gt;9.3859291076660156e+001&lt;/Angle&gt;
  &lt;Class&gt;0&lt;/Class&gt;
  &lt;Octave&gt;-1&lt;/Octave&gt;
  &lt;Pt_X&gt;1.7674386596679687e+002&lt;/Pt_X&gt;
  &lt;Pt_Y&gt;6.4983604431152344e+001&lt;/Pt_Y&gt;
  &lt;Response&gt;0.&lt;/Response&gt;
  &lt;Size&gt;1.2262072563171387e+001&lt;/Size&gt;
  &lt;Angle&gt;9.8604904174804688e+001&lt;/Angle&gt;
  &lt;Class&gt;0&lt;/Class&gt;
  &lt;Octave&gt;-1&lt;/Octave&gt;
  &lt;Pt_X&gt;1.1859683990478516e+002&lt;/Pt_X&gt;
  &lt;Pt_Y&gt;6.6855834960937500e+001&lt;/Pt_Y&gt;
  &lt;Response&gt;0.&lt;/Response&gt;
  &lt;Size&gt;1.1112688064575195e+001&lt;/Size&gt;
  ...
  </code></pre>
  
  <p>Expected Output</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;opencv_storage&gt;
  &lt;Total_Images&gt;1&lt;/Total_Images&gt;
  &lt;Node&gt;image_0
      &lt;Width&gt;500&lt;/Width&gt;
      &lt;Height&gt;266&lt;/Height&gt;
      &lt;Keypoint_Size&gt;268&lt;/Keypoint_Size&gt;
      &lt;KeyPoint&gt;
              &lt;Angle&gt;8.7332672119140625e+001&lt;/Angle&gt;
          &lt;Class&gt;0&lt;/Class&gt;
          &lt;Octave&gt;-1&lt;/Octave&gt;
          &lt;Pt_X&gt;1.7401049804687500e+002&lt;/Pt_X&gt;
          &lt;Pt_Y&gt;6.5084960937500000e+001&lt;/Pt_Y&gt;
          &lt;Response&gt;0.&lt;/Response&gt;
          &lt;Size&gt;1.1386331558227539e+001&lt;/Size&gt;
      &lt;/KeyPoint&gt;
      &lt;KeyPoint&gt;
          &lt;Angle&gt;9.3859291076660156e+001&lt;/Angle&gt;
          &lt;Class&gt;0&lt;/Class&gt;
          &lt;Octave&gt;-1&lt;/Octave&gt;
          &lt;Pt_X&gt;1.7674386596679687e+002&lt;/Pt_X&gt;
          &lt;Pt_Y&gt;6.4983604431152344e+001&lt;/Pt_Y&gt;
          &lt;Response&gt;0.&lt;/Response&gt;
          &lt;Size&gt;1.2262072563171387e+001&lt;/Size&gt;
      &lt;/KeyPoint&gt;
      &lt;KeyPoint&gt;
          &lt;Angle&gt;9.8604904174804688e+001&lt;/Angle&gt;
          &lt;Class&gt;0&lt;/Class&gt;
          &lt;Octave&gt;-1&lt;/Octave&gt;
          &lt;Pt_X&gt;1.1859683990478516e+002&lt;/Pt_X&gt;
          &lt;Pt_Y&gt;6.6855834960937500e+001&lt;/Pt_Y&gt;
          &lt;Response&gt;0.&lt;/Response&gt;
          &lt;Size&gt;1.1112688064575195e+001&lt;/Size&gt;
      &lt;/KeyPoint&gt;
      ...
  &lt;/Node&gt;
  </code></pre>
  
  <p>Thanks</p>