The requested page is not available for the requested platform. You are viewing the content for Default platform.

Bind a Report to an XML File

  • 2 min 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. Start Microsoft Visual Studio and create a new application, or open an existing one.
  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 Database. 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. 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.

    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 Components node. The Field List reflects the data source's 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