Load data report from xml file

Stimulsoft Reports.JS discussion
Post Reply
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Load data report from xml file

Post by felipemoreira »

Hi.
I have a report with datasource named "Names", with 2 fields: "name" and "age".
Read json file files works but xml don´t.

My xml file:

Code: Select all

<Names>
   <name>Agencia 1</name>
    <age>2</age>
</Names>
It shows a blank report.
I'm sure that my xml file is not on format expected.

Thanks!
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Load data report from xml file

Post by HighAley »

Hello.

Please, send us a sample with JSON and XML files where we could see all described above.

Thank you.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Load data report from xml file

Post by felipemoreira »

Hi HighAley.

My json data:

Code: Select all

{
    "Names": [{
        "name": "john",
        "age" : 30
    }, {
        "name": "Abel",
        "age" : 23
    }, {
        "name": "Joe",
        "age" : 34
    }, {
        "name": "Joseph",
        "age" : 12
    }]
}
My xml data:

Code: Select all

<Names>
      <name>Agencia 1</name>
       <age>2</age>
</Names>
My code to load json data:

Code: Select all

var report = new Stimulsoft.Report.StiReport();
var dataSet = new Stimulsoft.System.Data.DataSet("SimpleDataSet");
dataSet.readJsonFile("data/namejson.json");
report.regData(dataSet.dataSetName, "", dataSet);
report.loadFile("js/Names.mrt");
var viewer = new Stimulsoft.Viewer.StiViewer(null, "StiViewer", false);
viewer.report = report;
viewer.renderHtml("report_designer");
My code to load xml data:

Code: Select all

var report = new Stimulsoft.Report.StiReport();
var dataSet = new Stimulsoft.System.Data.DataSet("SimpleDataSet");
dataSet.readXmlFile("data/port_xml.xml");
report.regData(dataSet.dataSetName, "", dataSet);
report.loadFile("js/Names.mrt");
var viewer = new Stimulsoft.Viewer.StiViewer(null, "StiViewer", false);
viewer.report = report;
viewer.renderHtml("report_designer");
report.dictionary.databases.clear();
Follow my report attached.

Thanks.
Attachments
Names.mrt
(1.7 KiB) Downloaded 210 times
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Load data report from xml file

Post by felipemoreira »

Follow xml file as datasource attached.
Attachments
port_xml.xml
Xml data
(63 Bytes) Downloaded 245 times
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Re: Load data report from xml file

Post by Ivan »

Hello,

The JS has no native support for the XML format, so we ported simple implementation from the Net.
Therefore, the XML file must have the DataSet name element as the root element.
Please modify your XML-file:

Code: Select all

<DataSetName>
	<Names>
		<name>Agencia 1</name>
		<age>2</age>
	</Names>
</DataSetName>
Thank you.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Load data report from xml file

Post by felipemoreira »

It worked, thanks Ivan.
Andrew
Posts: 4107
Joined: Fri Jun 09, 2006 3:58 am

Re: Load data report from xml file

Post by Andrew »

Hello,

Thank you for letting us know about this.

Have a nice day!
Post Reply