ruby to_xml set root attributes
<p>I need to convert a ruby hash to xml. Here is the hash:</p>

<pre><code>hash = {
      "AffiliateInfo" =&gt; {
      "Username" =&gt; '123456',
      "Password" =&gt; "Mypass",
      "TrackingCampaign" =&gt; "MyTrackingCampaign",
      "Env" =&gt; "production"
    }
  }
</code></pre>

<p>and the xml I wanted to generate:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;InsuranceRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;AffiliateInfo&gt;
  &lt;Username&gt;12696&lt;/Username&gt;
  &lt;Password&gt;MyPassword&lt;/Password&gt;
  &lt;TrackingCampaign&gt;MyTrackingCampaign&lt;/TrackingCampaign&gt;
  &lt;LeadSourceID&gt;SourceID&lt;/LeadSourceID&gt;
  &lt;ProductionEnvironment&gt;true&lt;/ProductionEnvironment&gt;
  &lt;/AffiliateInfo&gt;
&lt;/InsuranceRequest&gt;
</code></pre>

<p>When I do:</p>

<pre><code>hash.to_xml(root: 'InsuranceRequest')
</code></pre>

<p>I get the following xml output</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;InsuranceRequest&gt;
  &lt;AffiliateInfo&gt;
    &lt;Username&gt;123456&lt;/Username&gt;
    &lt;Password&gt;Mypass&lt;/Password&gt;
    &lt;TrackingCampaign&gt;MyTrackingCampaign&lt;/TrackingCampaign&gt;
    &lt;Env&gt;production&lt;/Env&gt;
  &lt;/AffiliateInfo&gt;
&lt;/InsuranceRequest&gt;
</code></pre>

<p>The output is missing the properties of the root node attributes:</p>

<pre><code>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
</code></pre>

<p>I cannot add attributes to the root node. Is there a way to add these attributes using <code>to_xml</code> method?</p>

<p>Please suggest if there is any other means to solve my problem.</p>