A newer version of this page is available. Switch to the current version.

Binding Controls to XML Data

  • 2 minutes to read

This document explains how to display data from an XML file in a data-aware control.

Binding to XML Data

To bind a control to XML data, you need to create a DataSet object. This object provides methods that let you load XML files, streams containing XML data, etc. After data has been loaded into a DataSet, you can initialize the control's DataSource property with a table from that DataSet or the table's bound data view. Alternatively, you can set the DataSource and DataMember properties to the DataSet and the desired table name.

The image below illustrates binding to XML data.


An XML schema describes the type of data stored in an XML file. The schema can be stored along with data in a single XML file or in an external (.XSD) file. When data is loaded using DataSet methods, you must ensure that the schema is loaded as well. Otherwise, all loaded data will be treated as text and this can cause certain issues (such as editors not being assigned to columns in Grid Control depending upon the type of data, summaries will not be calculated in the PivotGrid control, etc.).

When a control is bound to XML data, changing cell values does not update the data source. Data changes are actually applied to the DataSet where the data was loaded. To apply changes to the data source, use the methods provided by the DataSet class. For instance, if data has been loaded from an XML file using the ReadXML method, you need to call the WriteXML method to overwrite the original file.

Note that binding to XML data can only be done at runtime. Specific controls, however, (e.g. Grid Control and XtraPivotGrid) let you preview data at design time via their Layout designer page.

See Also