How to load a report from XML

Stimulsoft Reports.Flex discussion
Locked
tonysameh
Posts: 10
Joined: Mon Nov 08, 2010 6:09 am
Location: Egypt

How to load a report from XML

Post by tonysameh »

I know this is trivial but sorry for my ignorance.

I have data in the form of XML. How to show it inside a report?
I tried the following:

Code: Select all

var x1:XML = 
					
						
							burger
							3.95
						
						
							fries
							1.45
						
					

				var xmlString:String = x1.toXMLString();   
				var xmlDoc:XMLDocument = new XMLDocument();
				xmlDoc.parseXML(xmlString);
				
			
				var report2: StiReport = new StiReport();
				report2.loadDocumentFromXML(xmlDoc);

				var rect: Rectangle = new Rectangle(100, 100, 900, 600);
				report2.showDialog(rect, "Customized ViewerFx", true, true);

And it shows an empty report.

What is the mistake?
And the bigger question is: Where in the document can I find any information about this topic?

Thanks
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

How to load a report from XML

Post by Vladimir »

Hello,

The report.loadDocumentFromXML() method loads a rendered report (.mdc format). For registering data the report.regData() method is used.

Please use the following code for data registering in the report:

Code: Select all

var xml: XMLDocument = new XMLDocument(x1);
report.regData("Data", "Data", xml.firstChild);
But this method will load only the data. For loading the report template (.mrt format), please use the report.loadReportFromXML() method or something similar.

Thank you.
tonysameh
Posts: 10
Joined: Mon Nov 08, 2010 6:09 am
Location: Egypt

How to load a report from XML

Post by tonysameh »

OK, now my complete code is as follows:

Code: Select all

				var x1:XML = 
					
						
							burger
							3.95
						
						
							fries
							1.45
						
					
				
				var xml:XMLDocument = new XMLDocument(x1);
				var report2: StiReport = new StiReport();
				report2.regData("Data", "Data", xml.firstChild);
	
				var rect: Rectangle = new Rectangle(100, 100, 900, 600);
				report2.showDialog(rect, "Customized ViewerFx", true, true);
still the report is shown but empty.

I miss something very basic. Thanks for your patience.
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

How to load a report from XML

Post by Vladimir »

Hello,

You load only data to report object, but you do not load the report template (.mrt file), which is made in the report designer. To load a report template, please use the report.loadReportFromXML(), report.loadReportFromString(), report.loadReportFromByteArray() methods.

In order to make a report template, please use the report designer. You can call it using the report.design() or report.designDialog() methods.

To display your data in the designer data dictionary, please use the report.dictionary.synhronize() method before calling the designer.

Thank you.
tonysameh
Posts: 10
Joined: Mon Nov 08, 2010 6:09 am
Location: Egypt

How to load a report from XML

Post by tonysameh »

So I should design the report in the designer using a sample data source (DataSource1) then save the .mrt template.
And then from inside FLEX code, I load the report and register the run time data with the same name "DataSource1"?
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

How to load a report from XML

Post by Vladimir »

Hello,

Yes, you are completely right.

Thank you.
Locked