title: Export Datatable to xml
body: <p>I have some <code>DataTables</code> that I want to export to a <code>xml</code> file. I can use <code>DataTable.WriteXml()</code> to output the contents of the <code>DataTables</code> to <code>XML</code>. </p>
  
  <p>I need to use a <code>Response object</code> as shown. I need to add attributes to the root of the output xml. Please help me with that. here is the code which I'm working on.</p>
  
  <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      Dim FileName1 As String = "Sheet1.xml"
      Response.Clear()
      Response.AddHeader("Content-Disposition", "attachment; filename=" &amp; FileName1)
      Response.ContentType = "text/xml"
      Dim ds As New DataSet("BuildingGroups")
      ds.EnforceConstraints = False
      Dim dtBuildingGroup As DataTable = Pipeline.Products.Components.BuildingGroupManager.GetBuildingGroupsToXML
      Dim result As String
      Dim sw As New StringWriter()
      dtBuildingGroup.TableName = "BuildingGroup"
      ds.Tables.Add(dtBuildingGroup)
      'Dim doc As New XmlDataDocument(ds)
      ds.WriteXml(sw)
      result = sw.ToString()
      Response.Write(result)
      Response.End()
  End Sub
  </code></pre>