title: XML from SQL table - SQL Server
body: <p>I am new to XML , The task is to generate xml similar to below mentioned from table :</p>
  
  <pre><code>&lt;A&gt;
  &lt;a1&gt;1&lt;/a1&gt;
  &lt;a2&gt;2&lt;/a2&gt;
  &lt;a3 type="xyz"&gt;abc&lt;/a3&gt;
  &lt;B&gt;
      &lt;b1&gt;11&lt;/b1&gt;
      &lt;b2 ID ="b2_product" name="clothing" &gt;
          &lt;c1&gt;
              &lt;d1 type = "xlr1"&gt;d11&lt;/d1&gt;
              &lt;d1 type = "xlr2"&gt;d12&lt;/d1&gt;
          &lt;/c1&gt;
      &lt;/b2&gt;
  &lt;/B&gt;
  </code></pre>
  
  <p></p>
  
  <p>Sql Table for this is :</p>
  
  <pre><code>Table A:
  
  a1   a2   a3_type    a3     b1      b2_ID       b2_name     xlr1    xlr2
  
  1    2     xyz      abc     11   b2_product     clothing    d11     d12
  </code></pre>
  
  <p>How to write SQL to generate XML from this table in given format of xml only.</p>