Active Reports 13 Web Designer And Page Reports

Posted by: nicolaas.coetzee on 5 September 2019, 12:22 am EST

    • Post Options:
    • Link

    Posted 5 September 2019, 12:22 am EST - Updated 30 September 2022, 8:34 am EST

    How should I create a XML data source in order to allow repeating elements to work correctly? Currently I am creating the XML data source like this

    private DataObject GetXMLDataSource(ReportPreviewOptions reportPreviewOptions) {
                string xmlData = Encoding.UTF8.GetString(Convert.FromBase64String(reportPreviewOptions.Parameters)); // The parameters are received from the front end
                DataSource dataSource = new DataSource();
                dataSource.Name = "XML Data Source";
                dataSource.ConnectionProperties.DataProvider = "XML";
                dataSource.ConnectionProperties.ConnectString = $"xmldata={xmlData}";
    
                DataSet dataSet = new DataSet();
                XDocument xmlDocument = XDocument.Parse(xmlData);
                dataSet.Name = dataSource.Name;
                dataSet.Query.CommandType = QueryCommandType.Text;
                XElement recordItem = xmlDocument.Descendants(reportPreviewOptions.XMLRecordTag).FirstOrDefault();
                dataSet.Query.CommandText = (recordItem).GetAbsoluteXPath().Replace("[1]", ""); //CommandText evaluates to "\people\person"
                dataSet.Query.DataSourceName = dataSource.Name;
                foreach (XName name in xmlDocument.Root.DescendantNodes().OfType<XElement>().Select(x => x.Name).Distinct()) {
                    XElement xElement = xmlDocument.Descendants(name).FirstOrDefault();
    //This loops each distinct node of the XML structure and returns the XPath to the node i.e. /people/person/name/given
                    if (xElement == null) {
                        throw new Exception();
                    }
                    Field field = new Field();
                    string xmlPath = xElement.GetAbsoluteXPath().Replace("[1]", "");
                    field.DataField = xmlPath;
                    field.Name = name.LocalName;
                    dataSet.Fields.Add(field);
                }
                return new DataObject() { DataSet = dataSet, DataSource = dataSource };
            }
    
    

    And this results in a datasource like this on the designer

    So it looks great in the designer and is easy to map but when I preview the data I get the wrong information. This is the sample XML I am using taken from the AR documentation ```







    John

    Doe









    Jane

    Smith





    So based on that XML I am expecting two rows with different details. But instead I am getting two rows repeating the first row details as seen below
    [img]https://gccontent.blob.core.windows.net/forum-uploads/file-023cd2f3-6b0e-47c0-bbcc-c1730287938c.PNG[/img]
  • Posted 5 September 2019, 9:49 pm EST

    Hello Nicolaas,

    Could you please confirm how are you pass the XML data source to report in detail which I think is the root cause of this issue? If possible could you please share the striped sample with us so that I can replicate the issue at my end.

    Thanks.

  • Posted 8 September 2019, 6:41 pm EST

    Hi Mohitg

    I am using the “WebDesigner_MVC(Core)” sample as a base… So on the design time I am providing some XML data to use as a “template”. This is only set once when the DataSource is created as seen in my code example in my previous post ```

    dataSource.ConnectionProperties.ConnectString = $“xmldata={xmlData}”;

    Then at preview time I overwrite the report XMLData with data received from the UI in order to make the XML data source handle "dynamic data sets". The new Data is expected to follow the same template as the hard coded template.
    
    See attached zip for the code example
    [zip filename="Stipped Reporting Service.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-4058da9d-4d1e-4815-8fa7-19b72ef97cf1.zip[/zip]
    
    Note this is a heavily stripped down version so stuff like saving and previewing is not working. But it should allow you to Add the XML datasource so that you can see how it would work.
  • Posted 8 September 2019, 9:39 pm EST

    Hello Nicolaas,

    Thanks for the stripped sample.

    Actually problem is found in the following line of code in GetXMLDataSource method:

    field.DataField = xmlPath;

    It set the following value to “DataField” property of the field:

    /people/person

    /people/person/name

    /people/person/name/given

    /people/person/name/family

    the value of “DataField” property of the field should be:

    person

    name

    given

    family.

    Thanks,

    Mohit

  • Posted 9 September 2019, 1:28 am EST

    Hi Mohitg

    Thanks for your clarification. That solved my problem.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels