[ Team LiB ] Recipe Formatting Column Values When Outputting Data as XML Problem You need to save some of the columns in a DataTable as attributes instead of elements when you write out the data as XML. Solution Use the ColumnMapping property. | Team LiB Recipe Formatting Column Values When Outputting Data as XML Problem You need to save some of the columns in a DataTable as attributes instead of elements when you write out the data as XML. Solution Use the ColumnMapping property. The sample code contains two event handlers Sets up the sample by creating a DataSet containing the first two records of the Customers table from Northwind. Refresh Iterates over all of the columns in all of the Customers tables and sets the ColumnMapping property to the specified value. The ColumnMapping for the ContactName column is then set to the specified value. The XML output for the DataSet is displayed. The C code is shown in Example 8-13. Example 8-13. File Namespaces variables and constants using System using using using private DataSet ds . . . private void XmlElementsOrAttributesForm_Load object sender e ds new DataSet CustomersDataSet Get the top two rows from the Customers table. SqlDataAdapter da new SqlDataAdapter SELECT TOP 2 FROM Customers S ql_ConnectString ds Customers private void refreshButton_Click object sender e Set the mapping type for each column in the table. foreach DataTable table in foreach DataColumn column in if else if else if Set the mapping type for the ContactName column. DataColumn dc Customers .Columns ContactName if else if else if columnHiddenRadioButton. Checked else if .