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.
Note
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
The Data Source Wizard allows you to bind a Report to an XML representation of a DataSet object.
You can use this approach if your XML file:
- Includes an XSD schema.
- Is an XML-serialized DataSet object.
- Contains simple data types.
Tip
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. For more information, review the following help topic: Get Started with DevExpress Reporting.
- 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 XML file. Click Next.
On the next page, select the first option to create a new data connection. Click Next.
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.
The Report Explorer displays the created SQL data source in the Data Sources node. The Field List reflects the data source hierarchy.
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);
Tip
If your XML file has an unsupported structure, you can manually parse it and bind a report to an ObjectDataSource.