---
title: "Crystal Report with XML Data Source"  
description: "This article will show you how to report XML data with Crystal Reports and Windows Forms client.  Following is the partial listing from the sample"  
author: "Chris Anderson"  
published: 2011-08-24  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/611/crystal-report-with-xml-data-source  
category: "crystal report"  
tags: ["crystal report"]  
reading_time: 3 minutes  

---

# Crystal Report with XML Data Source

This article will show you how to report XML data with [**Crystal Reports**](https://www.mindstick.com/articles/601/formula-field-in-crystal-report) and Windows Forms client.\

Following is the partial listing from the sample [XML file](https://www.mindstick.com/articles/75/how-to-read-and-write-xml-file-through-c-sharp) which I am using in the demo:

```
<Student>             <Name>Rohit Kesharwani</Name>
               <Course>GNIIT</Course>                <Age>20</Age>             <Hobby>Cricket</Hobby>
 </Student>
```

Add a DataSet to the project. Select **Add -> New Item ->** DataSet from Solution [Explorer](https://yourviews.mindstick.com/view/81617/now-it-is-time-to-say-goodbye-to-internet-explorer).

![Crystal Report with XML Data Source](https://www.mindstick.com/mindstickarticle/3f505f6a-52cb-4837-88b4-fa95f2e00c18/images/ce8b0264-dfa3-48c5-b182-dd7cecdafbe9.png)

Add [DataTable](https://www.mindstick.com/articles/122/datatable) to DataSet from the toolbox. Now add columns to the DataTable\
**Right-click on DataTable1 and select Add -> Column to start adding the columns to the DataTable.**

![Crystal Report with XML Data Source](https://www.mindstick.com/mindstickarticle/3f505f6a-52cb-4837-88b4-fa95f2e00c18/images/84cb1940-84de-42a7-b78b-f516a541a50d.png)

Now add a [**DataSet as a source of data for a report**](https://www.mindstick.com/articles/1117/crud-operation-using-modal-dialog-in-asp-dot-net-mvc). You’ll start with Right-Clicking on any open area on Report Designer -> [Database](https://www.mindstick.com/articles/71/how-to-create-xml-file-of-database-in-c-sharp) -> Database Expert…

As a result of this action, the Database Expert [dialog box](https://www.mindstick.com/blog/157/dialog-box-in-dot-net) will appear. You can click on Project Data and expand the node ADO.NET DataSet.

Select the DataTable from DataSet and click on the “>” button to move it to the [selected tables](https://www.mindstick.com/forum/159136/how-can-i-create-backup-script-for-selected-tables-in-oracle) section on the right-hand side.

![Crystal Report with XML Data Source](https://www.mindstick.com/mindstickarticle/3f505f6a-52cb-4837-88b4-fa95f2e00c18/images/a0832c3e-c85f-491f-98ba-7662366be2cc.png)

Once the report source is specified, all we have to do is [drag and drop](https://www.mindstick.com/forum/454/how-to-drag-and-drop-multiple-image-from-one-canvas-to-onther-canvas-in-html5) the fields from DataTable inside Detail section on report designer surface.

You can drag and drop all the fields from DataTable from Field Explorer inside the details section.

![Crystal Report with XML Data Source](https://www.mindstick.com/mindstickarticle/3f505f6a-52cb-4837-88b4-fa95f2e00c18/images/2a26ffb3-4a6b-4bfb-9b98-0c724eeb1881.png)

You can add a crystalReportViewer to the Form1 as follows:

Drag ToolBox -> [Reporting](https://www.mindstick.com/articles/12967/portable-reporting-systems-and-mobile-device-management) -> CrystalReportViewer and drop it on Form1. This step

will create a new instance of crystalReportViewer with the name

crystalReportViewer1.

![Crystal Report with XML Data Source](https://www.mindstick.com/mindstickarticle/3f505f6a-52cb-4837-88b4-fa95f2e00c18/images/0f845c04-e61f-45ff-9be2-2e63c7a5b198.png)

After the design part, add code in the **Form.cs** to read the xml data in the Dataset.

```
private void Form1_Load(object sender, EventArgs e){    try      {       DataSet dsSet = new DataSet();      dsSet.Tables.Add("DataTable1");
      //create temp dataset to read xml data     DataSet dsTempReport = new DataSet();
    // using ReadXml method of DataSet read XML data from Student.xml file     dsTempReport.ReadXml(@"D:\rohit\Student.xml");
   // copy XML data from temp dataset to our typed data set   dsSet.Tables[0].Merge(dsTempReport.Tables[0]);
    //prepare report for preview    CrystalReport1 rptXml = new CrystalReport1();    rptXml.SetDataSource(dsSet.Tables[0]);     crystalReportViewer1.ShowGroupTreeButton = false;   crystalReportViewer1.ReportSource = rptXml;       }
    catch (Exception ex)   {     MessageBox.Show(ex.Message);   } }
```

Let’s build and run the example to see the output.\

![Crystal Report with XML Data Source](https://www.mindstick.com/mindstickarticle/3f505f6a-52cb-4837-88b4-fa95f2e00c18/images/25a15c6c-46f5-4d2d-ae29-0f6e225cd655.png)

---

Original Source: https://www.mindstick.com/articles/611/crystal-report-with-xml-data-source

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
