clive.haynes_1 Posted March 23, 2015 Share Posted March 23, 2015 Hi there, Does anyone have an example of passing an XMl datasource from a main report to a subreport. I used to use the following in the data Source Expression field of the sub report parametersnew net.sf.jasperreports.engine.data.JRXmlDataSource("rmc.xml", "/mytexts/text") and it worked for a while but now I keep getting the following any concrete example would be appreciatednet.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : new net.sf.jasperreports.engine.data.JRXmlDataSource("rmc.xml", "/mytexts/text") at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:467) at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$18(ReportControler.java:442) at com.jaspersoft.studio.editor.preview.view.control.ReportControler$4.run(ReportControler.java:334) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : new net.sf.jasperreports.engine.data.JRXmlDataSource("rmc.xml", "/mytexts/text") at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:263) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:611) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:579) at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1016) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:431) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:326) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:455) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummaryNoLastFooterSamePage(JRVerticalFiller.java:1070) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummary(JRVerticalFiller.java:1031) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportEnd(JRVerticalFiller.java:295) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:131) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:540) at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFill.run(BaseFillHandle.java:120) at java.lang.Thread.run(Unknown Source)Caused by: net.sf.jasperreports.engine.JRException: Input stream not found at : rmc.xml at net.sf.jasperreports.repo.RepositoryUtil.getInputStreamFromLocation(RepositoryUtil.java:159) at net.sf.jasperreports.engine.data.JRXmlDataSource.<init>(JRXmlDataSource.java:318) at net.sf.jasperreports.engine.data.JRXmlDataSource.<init>(JRXmlDataSource.java:337) at net.sf.jasperreports.engine.data.JRXmlDataSource.<init>(JRXmlDataSource.java:332) at toto_1427126910966_497945.evaluate(toto_1427126910966_497945:177) at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:250) ... 14 more Link to comment Share on other sites More sharing options...
morlandin Posted March 24, 2015 Share Posted March 24, 2015 Can you provide the xml, the main report and the subreport so we can debug to find why beofre it worked and now not? Link to comment Share on other sites More sharing options...
clive.haynes_1 Posted March 24, 2015 Author Share Posted March 24, 2015 Master report<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.0.1.final using JasperReports Library version 6.0.0 --><!-- 2015-03-24T13:56:25 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Master" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d32622b3-ebdd-4da1-959f-a925e4180e62"><property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/><queryString><![CDATA[]]></queryString><background><band splitType="Stretch"/></background><title><band height="25" splitType="Stretch"/></title><summary><band height="323" splitType="Stretch"><subreport><reportElement x="10" y="40" width="200" height="200" uuid="55d17d32-65a4-4bc1-899d-07eefac87d89"/><dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRXmlDataSource("rmc.xml", "/mytexts/text")]]></dataSourceExpression><subreportExpression><![CDATA["rmc.jasper"]]></subreportExpression></subreport></band></summary></jasperReport>SubReport<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.0.1.final using JasperReports Library version 6.0.0 --><!-- 2015-03-24T14:01:18 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="rmc" columnCount="2" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="272" columnSpacing="10" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ac2e4382-ca7b-42de-8ef5-61233a029eb4"> <property name="com.jaspersoft.studio.unit." value="pixel"/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="rmc"/> <parameter name="ReportName" class="java.lang.String" isForPrompting="false"/> <queryString language="xpath2"> <![CDATA[/mytexts/text]]> </queryString> <field name="id_1" class="java.lang.String"> <fieldDescription><![CDATA[@id]]></fieldDescription> </field> <field name="title_1" class="java.lang.String"> <fieldDescription><![CDATA[title]]></fieldDescription> </field> <field name="section_1" class="java.lang.String"> <fieldDescription><![CDATA[section]]></fieldDescription> </field> <variable name="headerCount" class="java.lang.Integer" calculation="Count"> <variableExpression><![CDATA[$V{headerCount}]]></variableExpression> <initialValueExpression><![CDATA[0]]></initialValueExpression> </variable> <group name="Group1"> <groupExpression><![CDATA[$F{id_1}]]></groupExpression> <groupHeader> <band height="50"> <textField isStretchWithOverflow="true"> <reportElement positionType="Float" x="10" y="20" width="250" height="30" uuid="00b11210-114f-4dae-ae76-92a98eed2e0b"/> <textElement textAlignment="Justified"/> <textFieldExpression><![CDATA[$F{section_1}]]></textFieldExpression> </textField> <textField isBlankWhenNull="true"> <reportElement x="10" y="0" width="250" height="20" isRemoveLineWhenBlank="true" uuid="96f38193-5674-4b91-8769-0debc542ebc0"/> <textElement> <font isBold="true"/> </textElement> <textFieldExpression><![CDATA[$F{title_1}]]></textFieldExpression> </textField> </band> </groupHeader> </group> <background> <band splitType="Stretch"/> </background> <pageHeader> <band height="47"> <rectangle> <reportElement x="10" y="30" width="544" height="11" backcolor="#E0E0E0" uuid="78ad6d91-603c-4195-9e01-231d73b4fb3c"> <property name="local_mesure_unitwidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> </reportElement> <graphicElement> <pen lineColor="#E0E0E0"/> </graphicElement> </rectangle> </band> </pageHeader> <pageFooter> <band height="20"> <textField> <reportElement x="10" y="0" width="545" height="20" forecolor="#99CCFF" uuid="ccae5d78-1d60-4d70-81e4-a3abc342da45"/> <textElement> <font fontName="Arial" size="8"/> </textElement> <textFieldExpression><![CDATA[$P{ReportName}]]></textFieldExpression> </textField> <textField evaluationTime="Master"> <reportElement x="480" y="0" width="75" height="20" forecolor="#99CCFF" uuid="fae8f096-2c9c-46c4-9ef0-0f2c72e3409f"/> <textElement> <font fontName="Arial" size="8" isBold="false"/> </textElement> <textFieldExpression><![CDATA["Page "+$V{MASTER_CURRENT_PAGE}+" of "+$V{MASTER_TOTAL_PAGES}]]></textFieldExpression> </textField> </band> </pageFooter> <summary> <band height="50"/> </summary></jasperReport>XML File <mytexts> <text id="0"> <title>The standard Lorem Ipsum passage</title><section> <![CDATA[The standard Lorem Ipsum passageSed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam,eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur,vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?]]></section></text></mytexts> Link to comment Share on other sites More sharing options...
morlandin Posted March 24, 2015 Share Posted March 24, 2015 The problem is that JasperReports can't the xml file since you are not providing the absolute path, you have two choices-The first one is to provide the context of the current report, in this way it will look inside the project folder of the report to search the resource when the path is relative, like this: new net.sf.jasperreports.engine.data.JRXmlDataSource((JasperReportsContext)$P{JASPER_REPORTS_CONTEXT}, "rmc.xml", "/mytexts/text") -Provide the absolute path for your jrxml, like this: new net.sf.jasperreports.engine.data.JRXmlDataSource( "C:/Users/Marco/workspace/MyReports/rmc.xml", "/mytexts/text") Link to comment Share on other sites More sharing options...
clive.haynes_1 Posted March 24, 2015 Author Share Posted March 24, 2015 Hi there Many many thanks for your help. Outstanding it works Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now