title: Export SQL Server 2012 database to XML with foreign keys
body: <p>What I wish to do on top of exporting to xml as in this thread <a href="https://stackoverflow.com/questions/3952469/export-xml-from-sql-server">SQL DB to XML</a> is that for every row that is a foreign key, I also want to include the xml represenation of that reference, too.</p>
  
  <p>For example a table Employee:</p>
  
  <pre><code>EID(PK)   Name  Supervisor(FK)  
    1       John       NULL  
    2       Kevin       1
  </code></pre>
  
  <p>Should output an XML as:</p>
  
  <pre><code>&lt;Employees&gt;  
      &lt;Employee&gt; 
         &lt;EID&gt;1&lt;/EID&gt;  
         &lt;Name&gt;John&lt;/Name&gt;
         &lt;Supervisor&gt;NULL&lt;/Supervisor&gt;
      &lt;/Employee&gt;
      &lt;Employee&gt;
         &lt;EID&gt;2&lt;/EID&gt;
         &lt;Name&gt;Kevin&lt;/Name&gt;
         &lt;Supervisor&gt;
              &lt;EID&gt;1&lt;/EID&gt;
              &lt;Name&gt;John&lt;/Name&gt;
                 &lt;Supervisor&gt;NULL&lt;/Supervisor&gt;
         &lt;/Supervisor&gt;
      &lt;/Employee&gt;
  &lt;/Employees&gt;
  </code></pre>
  
  <p>I am looking for a solution either in C# (if I can find a way to know a DataColumn is a foreign key), or SSIS.</p>