我有一些 DataTables
,想要将其导出为 xml
文件。我可以使用 DataTable.WriteXml()
将 DataTables
的内容输出到 XML
。
我需要使用如下所示的 Response object
。我需要在输出的 xml 根元素中添加属性。请帮我完成这个任务。以下是我正在使用的代码:
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=" & 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