DataTable.WriteXml Method (TextWriter, Boolean)
Assembly: System.Data (in System.Data.dll)
The WriteXml method provides a way to write either data only, or both data and schema from a DataTable into an XML document, whereas the WriteXmlSchema method writes only the schema. To write both data and schema, use one of the overloads that includes the XmlWriteMode parameter, and set its value to WriteSchema.
Normally the WriteXml method writes the data only for the current table. To write the data for the current table and all its descendant, related tables, call the method with the writeHierarchy parameter set to true.
The following console application creates two DataTable instances, adds each to a DataSet, creates a DataRelation relating the two tables, and then uses the method to write the data contained within the parent table to a TextWriter. The example demonstrates the behavior when setting the writeHierarchy parameter to true.
Available since 2.0