XML output with Filestorage in OpenCV
<p>I want to output an XML file using OpenCV filestorage class. But the output is not same as I want. I need help to write my data in a different format. Following is the Function code.</p>

<pre><code>void write_data(int x, int y, int w, int h, int count, int region)
{

    FileStorage fs("data.xml", FileStorage::APPEND);
    fs &lt;&lt;"frame";
    fs &lt;&lt; "{" &lt;&lt; "number" &lt;&lt;count
    &lt;&lt; "}";

    fs &lt;&lt; "box";                              
    fs &lt;&lt; "{" &lt;&lt; "h" &lt;&lt; h;
    fs &lt;&lt;        "w" &lt;&lt; w;
    fs &lt;&lt;        "xc"  &lt;&lt; x;
    fs &lt;&lt;        "yc"  &lt;&lt; y 
    &lt;&lt; "}";

    fs.release();                                       
    cout &lt;&lt; "Write Done." &lt;&lt; endl;
}
</code></pre>

<p>The output is </p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;opencv_storage&gt;
&lt;frame&gt;
 &lt;number&gt;1&lt;/number&gt;&lt;/frame&gt;
 &lt;box&gt;
    &lt;h&gt;52&lt;/h&gt;
    &lt;w&gt;52&lt;/w&gt;
    &lt;xc&gt;1156&lt;/xc&gt;
    &lt;yc&gt;336&lt;/yc&gt;&lt;/box&gt;
 &lt;!-- resumed --&gt;

&lt;frame&gt;
   &lt;number&gt;1&lt;/number&gt;&lt;/frame&gt;
   &lt;box&gt;
   &lt;h&gt;69&lt;/h&gt;
   &lt;w&gt;69&lt;/w&gt;
   &lt;xc&gt;1112&lt;/xc&gt;
   &lt;yc&gt;376&lt;/yc&gt;&lt;/box&gt;
&lt;!-- resumed --&gt;
</code></pre>

<p>Following is the desired output. For the value of "confident" I want generate a random number between 0.5000 to 1.0.</p>

<pre><code>    &lt;frame number="1"&gt;
    &lt;objectlist&gt;
        &lt;object confidence="0.89324"&gt;
            &lt;box h="52" w="52" xc="1156" yc="336" /&gt;
        &lt;/object&gt;
        &lt;object confidence="0.95996"&gt;
            &lt;box h="69" w="69" xc="1112" yc="376" /&gt;
        &lt;/object&gt;
    &lt;/objectlist&gt;
&lt;/frame&gt;
&lt;frame number="2"&gt;
    &lt;objectlist&gt;
        &lt;object confidence="0.89324"&gt;
            &lt;box h="42" w="38" xc="521" yc="94" /&gt;
        &lt;/object&gt;
        &lt;object confidence="0.95996"&gt;
            &lt;box h="38" w="39" xc="633" yc="99" /&gt;
        &lt;/object&gt;
    &lt;/objectlist&gt;
&lt;/frame&gt;
</code></pre>