This documentation is archived and is not being maintained.
DataSet.GetXml Method
.NET Framework 1.1
Returns the XML representation of the data stored in the DataSet.
[Visual Basic] Public Function GetXml() As String [C#] public string GetXml(); [C++] public: String* GetXml(); [JScript] public function GetXml() : String;
Return Value
A string that is a representation of the data stored in the DataSet.
Remarks
Calling this method is identical to calling WriteXml with XmlWriteMode set to IgnoreSchema.
Note GetXml returns XML as a string, and therefore, requires more overhead than using WriteXml to write XML to a file.
Example
[Visual Basic, C#, C++] The following example creates a DataSet and DataTable, adds sample data, and then displays the data in XML format.
[Visual Basic] Private Shared Sub DemonstrateGetXml() ' Create a DataSet with one table containing two columns and 10 rows. Dim ds As DataSet = New DataSet("myDataSet") Dim t As DataTable = ds.Tables.Add("Items") t.Columns.Add("id", Type.GetType("System.Int32")) t.Columns.Add("Item", Type.GetType("System.String")) ' Add ten rows. Dim r As DataRow Dim i As Integer For i = 0 To 9 r = t.NewRow() r("id") = i r("Item")= "Item" & i t.Rows.Add(r) Next ' Display the DataSet contents as XML. Console.WriteLine( ds.GetXml() ) End Sub [C#] private static void DemonstrateGetXml() { // Create a DataSet with one table containing two columns and 10 rows. DataSet ds = new DataSet("myDataSet"); DataTable t = ds.Tables.Add("Items"); t.Columns.Add("id", typeof(int)); t.Columns.Add("Item", typeof(string)); // Add ten rows. DataRow r; for(int i = 0; i <10;i++) { r = t.NewRow(); r["id"]= i; r["Item"]= "Item" + i; t.Rows.Add(r); } // Display the DataSet contents as XML. Console.WriteLine( ds.GetXml() ); } [C++] public: static void DemonstrateGetXml() { // Create a DataSet with one table containing two columns and 10 rows. DataSet* ds = new DataSet(S"myDataSet"); DataTable* t = ds->Tables->Add(S"Items"); t->Columns->Add(S"id", __typeof(int)); t->Columns->Add(S"Item", __typeof(String)); // Add ten rows. DataRow* r; for (int i = 0; i <10;i++) { r = t->NewRow(); r->set_Item(i,r); r->Item[S"Item"]= S"Item {0}", i; t->Rows->Add(r); } // Display the DataSet contents as XML. Console::WriteLine(ds->GetXml()); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
See Also
Show: