Bind a Report to an XML File
- 2 minutes to read
This topic describes how to bind a report to an XML file at design time.
When a report is bound to an XML file, you cannot use the following data-shaping capabilities at the data source level:
- sort, group and filter data;
- use aggregate functions.
You can use this approach if your XML file:
Use the XmlDataPath property if your document contains complex data types embedded one into another.
Do the following to bind a report to an XML file at design time in Visual Studio:
Create a new application or open an existing application.
- Add a new blank report to it.
Click the report's smart tag. In the invoked actions list, expand the DataSource property's drop-down menu and click Add Report Data Source.
From the invoked Data Source Wizard, select Database. Click Next.
On the next page, select the first option to create a new data connection. Click Next.
Choose the XML file as a data provider and specify the path to the Cars.xml database file. You can find this file in the XtraReports installation. Click Next.
Click Next to save the connection string to the configuration file.
On the next page, you can choose which tables, views and/or stored procedures to add to the report. You can also use the Query Builder to construct custom queries. Expand the Tables category, select the Cars item and click Finish to exit the wizard.
If your XML file is missing a schema, you can write it with the following code:
DataSet set = new DataSet(); set.ReadXml("MyDocument.xml"); set.WriteXml("MyDocument.xml", XmlWriteMode.WriteSchema);
If your XML file has an unsupported structure, you can manually parse it and bind a report to an ObjectDataSource.