Skip to main content

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:

  1. Create a new application or open an existing application. For more information, review the following help topic: Get Started with DevExpress Reporting.

  2. Add a new blank report to it.
  3. 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.

    how-to-ef-datasource01

  4. From the invoked Data Source Wizard, select XML file. Click Next.

    ReportWizard-SelectDataSourceType

  5. On the next page, select the first option to create a new data connection. Click Next.

    data-source-wizard-specify-data-connection

  6. Specify the path to the Cars.xml database file. You can find this file in the XtraReports installation. Click Next.

    how-to-sql-data-source01

  7. Click Next to save the connection string to the configuration file.

  8. 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.

    data-source-wizard-xml-file-select-query-page

The Report Explorer displays the created SQL data source in the Data Sources node. The Field List reflects the data source hierarchy.

how-to-sql-data-source02

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.

See Also