This is a migrated thread and some comments may be shown as answers.

XML as Report Data Source

1 Answer 561 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
israel
Top achievements
Rank 1
israel asked on 26 Jul 2016, 06:15 PM

Hi everybody.

recently I was working in a project where the requirement was save "trdx" files into a DB and show them in a asp.net web form application. As additional information, the data to populate the reports were in XML files.

so I realized to late that "Telerik reporting" doesn't accept xml as datasource or at least I couldn't find a direct way to achieve that. I read that you can transform the xml into objectdatasource but it was little complicated due the dynamism in the project.

at the end I decided to work with a user function that basically accept two parameters 

- XPathExpression => the xpath query to find the data in the xml string

- xmlDocument  => the xml string, I pass it to my report by a parameter.

The function :   

[Function(Category = "XPath", Namespace = "XmlTelerikReporting", Description = "Find the information from the default report parameter XmlDataSource using XPath expressions ")]
  public static object XmlValue(string XPathExpression, string xmlDocument)
  {
 
      #region XmlValue
      try
      {
          XmlDocument xmlDoc = new XmlDocument();
          xmlDoc.LoadXml(xmlDocument);
          xmlDoc.DocumentElement.RemoveAttribute("xmlns");
          XmlDocument newDom = new XmlDocument();
          newDom.LoadXml(System.Text.RegularExpressions.Regex.Replace(
                  xmlDoc.OuterXml
                  , @"(xmlns:?[^=]*=[""][^""]*[""])",
                  "",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline));
 
 
          object xmlXPathValue = newDom.SelectSingleNode(XPathExpression) != null ? newDom.SelectSingleNode(XPathExpression).Value : null;
 
          return xmlXPathValue;
 
      }
      catch (Exception ex)
      {
          //a pretty ans secret way to catch exceptions
      }
      #endregion       
  }

 

How to use in expression:

 = XmlTelerikReporting.XmlValue(   "//@parametertofind" , Parameters.xmlDocument.Value   )

I will really  appreciate any feedback regarding to my code display above.

and it will be awesome if you implement something in telerik reporting in order to accept XML files as Datasource

Regards!

 

  

 

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 27 Jul 2016, 12:44 PM
Hi Israel,

There are data source components which provide a declarative manner to specify the data-retrieval method, and their settings are serialized in the report definition, but actual data objects are not. The reporting engine reads the data source components' settings and creates data objects at run-time.

To get data from an XML file, you can read it in a DataSet (msdn Loading a DataSet from XML) or deserialize it in a custom business object (msdn XmlSerializer.Deserialize Method (XmlReader)). The created data object can be used by data items via ObjectDataSource component. To use an ObjectDataSource in the Standalone Report Designer, please check the Extending Report Designer and the tutorials at the bottom of the help article.


Please feel free to log a feature request for having data source component reading serialized data. Features are considered for implementation based on the demand for them.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Report Designer (standalone)
Asked by
israel
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or