Page 1 of 1

How to load a report from XML

Posted: Mon Nov 08, 2010 9:24 am
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

How to load a report from XML

Posted: Tue Nov 09, 2010 1:02 am
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.

How to load a report from XML

Posted: Tue Nov 09, 2010 1:30 am
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.

How to load a report from XML

Posted: Tue Nov 09, 2010 5:44 am
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.

How to load a report from XML

Posted: Sun Nov 14, 2010 5:39 am
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"?

How to load a report from XML

Posted: Mon Nov 15, 2010 4:09 am
by Vladimir
Hello,

Yes, you are completely right.

Thank you.