WriteXml Method (TextWriter, Boolean)

DataTable.WriteXml Method (TextWriter, Boolean)

 

Writes the current contents of the DataTable as XML using the specified TextWriter. To save the data for the table and all its descendants, set the writeHierarchy parameter to true.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

member WriteXml : 
        writer:TextWriter *
        writeHierarchy:bool -> unit

Parameters

writer
Type: System.IO.TextWriter

The TextWriter with which to write the content.

writeHierarchy
Type: System.Boolean

If true, write the contents of the current table and all its descendants. If false (the default value), write the data for the current table only.

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.

System_CAPS_noteNote

An InvalidOperationException will be thrown if a column type in the DataRow being read from or written to implements IDynamicMetaObjectProvider and does not implement IXmlSerializable.

The following console application creates two DataTable instances, adds each to a DataSet, creates a DataRelation relating the two tables, and then uses the WriteXml 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.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show:
© 2016 Microsoft