Jump to content
Changes to the Jaspersoft community edition download ×

Subreports with XML Datasource Help!


Recommended Posts

By: Vzern - vzern

Subreports with XML Datasource Help!

2006-06-27 12:43

I need some help getting an XML datasource to work with subreports. or maybe I'm just trying to do a subreport incorrectly, but either way any help is welcomed.

 

below are my source files.

But what I'm trying to do is diplay the page number from the xml on the report (page is an xml tag, and number is an attribute), then from the subreport display all the rows of data from inside the page tag. Currently, all I am seeing is just the page numbers, but no rows of data. So what am I doing wrong? Oh and I'm doing all this inside of iReports 1.2.4, but I have tried compile and creating a pdf independent of iReports.

 

PS. After I get this stuff working. I'll try and write up a good example of the subreport with XML and submit it to both iReports and Jasperreports, so that other people won't have this problem.

 

Thanks,

Vzern

 

++++++++++++++++++++++++++++++++++++++++++++++++

MasterReport.jrxml

++++++++++++++++++++++++++++++++++++++++++++++++

 

<?xml version="1.0" encoding="UTF-8" ?>

<!-- Created with iReport - A designer for JasperReports -->

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport

name="MasterReport"

columnCount="1"

printOrder="Vertical"

orientation="Portrait"

pageWidth="595"

pageHeight="842"

columnWidth="535"

columnSpacing="0"

leftMargin="30"

rightMargin="30"

topMargin="20"

bottomMargin="20"

whenNoDataType="NoPages"

isTitleNewPage="false"

isSummaryNewPage="false">

<property name="ireport.scriptlethandling" value="0" />

<property name="ireport.encoding" value="UTF-8" />

<import value="java.util.*" />

<import value="net.sf.jasperreports.engine.*" />

<import value="net.sf.jasperreports.engine.data.*" />

 

<parameter name="SUBREPORT_DIR" isForPrompting="false" class="java.lang.String">

<defaultValueExpression ><![CDATA["C:\Documents and Settings\dduffek\Desktop\Jasper\PR\Fresh\"]]></defaultValueExpression>

</parameter>

<queryString language="xPath"><![CDATA[/Report/page]]></queryString>

 

<field name="pageNumber" class="java.lang.String">

<fieldDescription><![CDATA[@number]]></fieldDescription>

</field>

 

<background>

<band height="0" isSplitAllowed="true" >

</band>

</background>

<title>

<band height="0" isSplitAllowed="true" >

</band>

</title>

<pageHeader>

<band height="0" isSplitAllowed="true" >

</band>

</pageHeader>

<columnHeader>

<band height="0" isSplitAllowed="true" >

</band>

</columnHeader>

<detail>

<band height="101" isSplitAllowed="true" >

<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="23"

y="2"

width="162"

height="46"

key="textField-1"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement>

<font/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{pageNumber}]]></textFieldExpression>

</textField>

<subreport isUsingCache="true">

<reportElement

x="13"

y="58"

width="509"

height="38"

key="subreport-2"

isPrintWhenDetailOverflows="true"/>

<subreportParameter name="PageNumber">

<subreportParameterExpression><![CDATA[$F{pageNumber}]]></subreportParameterExpression>

</subreportParameter>

<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>

<subreportExpression class="java.lang.String"><![CDATA["Subreport.jasper"]]></subreportExpression>

</subreport>

</band>

</detail>

<columnFooter>

<band height="0" isSplitAllowed="true" >

</band>

</columnFooter>

<pageFooter>

<band height="0" isSplitAllowed="true" >

</band>

</pageFooter>

<summary>

<band height="0" isSplitAllowed="true" >

</band>

</summary>

</jasperReport>

 

+++++++++++++++++++++++++++++++++++++++++++++++++

Subreport.jrxml

+++++++++++++++++++++++++++++++++++++++++++++++++

 

<?xml version="1.0" encoding="UTF-8" ?>

<!-- Created with iReport - A designer for JasperReports -->

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport

name="Subreport"

columnCount="1"

printOrder="Vertical"

orientation="Portrait"

pageWidth="595"

pageHeight="842"

columnWidth="535"

columnSpacing="0"

leftMargin="30"

rightMargin="30"

topMargin="20"

bottomMargin="20"

whenNoDataType="NoPages"

isTitleNewPage="false"

isSummaryNewPage="false">

<property name="ireport.scriptlethandling" value="0" />

<property name="ireport.encoding" value="UTF-8" />

<import value="java.util.*" />

<import value="net.sf.jasperreports.engine.*" />

<import value="net.sf.jasperreports.engine.data.*" />

 

<queryString language="xPath"><![CDATA[/Report/page[@number =1]/table/body/row]]></queryString>

 

<field name="test" class="java.lang.String">

<fieldDescription><![CDATA[col[@cheadId =2]]]></fieldDescription>

</field>

<field name="LeaseNo" class="java.lang.String">

<fieldDescription><![CDATA[col[@cheadId =1]]]></fieldDescription>

</field>

 

<background>

<band height="0" isSplitAllowed="true" >

</band>

</background>

<title>

<band height="0" isSplitAllowed="true" >

</band>

</title>

<pageHeader>

<band height="0" isSplitAllowed="true" >

</band>

</pageHeader>

<columnHeader>

<band height="0" isSplitAllowed="true" >

</band>

</columnHeader>

<detail>

<band height="27" isSplitAllowed="true" >

<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="10"

y="0"

width="73"

height="27"

key="textField-2"

isPrintWhenDetailOverflows="true"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement>

<font isPdfEmbedded ="true"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{test}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="90"

y="0"

width="113"

height="27"

key="textField-3"

isPrintWhenDetailOverflows="true"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement>

<font isPdfEmbedded ="true"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{LeaseNo}]]></textFieldExpression>

</textField>

</band>

</detail>

<columnFooter>

<band height="0" isSplitAllowed="true" >

</band>

</columnFooter>

<pageFooter>

<band height="0" isSplitAllowed="true" >

</band>

</pageFooter>

<summary>

<band height="0" isSplitAllowed="true" >

</band>

</summary>

</jasperReport>

 

+++++++++++++++++++++++++++++++++++++++++++++++++

data.xml

+++++++++++++++++++++++++++++++++++++++++++++++++

 

<?xml version="1.0" encoding="utf-8" ?>

<Report NAME="OFP3330">

<page pageId="1" number="1" type="summary" reportName="DET.S.NET.BBLS">

<number>1</number>

<pageHeader>

<headerData headerId="1" name="Date">Prepared date:</headerData>

<headerData headerId="2" name="Date2">03/21/06</headerData>

</pageHeader>

<table>

<header>

<colName cheadId="1" name="name">name</colName>

<colName cheadId="2" name="day">Date</colName>

</header>

<body>

<row rowId="0">

<col cheadId="1" name="name">Acorn</col>

<col cheadId="2" name="day">02/04/06</col>

</row>

<row rowId="1">

<col cheadId="1" name="name">Nergum</col>

<col cheadId="2" name="day">02/05/06</col>

</row>

<row rowId="2">

<col cheadId="1" name="name">Nef</col>

<col cheadId="2" name="day">02/01/06</col>

</row>

<row rowId="3">

<col cheadId="1" name="name">Joyous</col>

<col cheadId="2" name="day">02/02/06</col>

</row>

 

</body>

</table>

</page>

<page pageId="2" number="2" type="normal" reportName="DTC.NET.VALUE">

<number>2</number>

<header>

<headerData headerId="1" name="Date">Prepared date:</headerData>

<headerData headerId="2" name="Date2">03/21/06</headerData>

</header>

<table>

<header>

<colName cheadId="1" name="ticket">Ticket</colName>

<colName cheadId="2" name="number">Meter</colName>

</header>

<body>

<row rowId="0">

<col cheadId="1" name="ticket">DYB_332</col>

<col cheadId="2" name="number">33445</col>

</row>

<row rowId="2">

<col cheadId="1" name="ticket">DYB_6334</col>

<col cheadId="2" name="number">99765</col>

</row>

</body>

</table>

</page>

</Report>

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...