XML as Report Data Source

2 posts, 0 answers
  1. israel
    israel avatar
    1 posts
    Member since:
    Aug 2013

    Posted 26 Jul 2016 Link to this post

    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
              XmlDocument xmlDoc = new XmlDocument();
              XmlDocument newDom = new XmlDocument();
                      , @"(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


    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





  2. Stef
    Stef avatar
    3610 posts

    Posted 27 Jul 2016 Link to this post

    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.

    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
Back to Top