java - Only one row is generated in report when data source is XML -


i'm trying generate report using xml data source. input xml file has 4 lines. jr engine generates report contains 1st row.

i have <detail> <band> ... </band> </detail> section data

my jrxml file looks this

<?xml version="1.0" encoding="utf-8" ?> <!doctype jasperreport public "//jasperreports//dtd report design//en" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">  <jasperreport name="simplereport">     <querystring language="xpath"><![cdata[/response/results]]></querystring>     <field name="field" class="java.lang.string">         <fielddescription><![cdata[//field]]></fielddescription>     </field>   <field name="count" class="java.lang.string">           <fielddescription><![cdata[//field[@count]]]></fielddescription>     </field>      <title>         <band height="50">             <statictext>           <reportelement x="0" y="0" width="180" height="15"/>             <textelement/>           <text><![cdata[report]]></text>         </statictext>         </band>     </title>   <pageheader>         <band/>     </pageheader>   <columnheader>         <band height="20">         <statictext>           <reportelement x="180" y="0" width="180" height="20"/>         <textelement>             <font isunderline="true"/>         </textelement>         <text><![cdata[event name]]></text>       </statictext>       <statictext>         <reportelement x="360" y="0" width="180" height="20"/>         <textelement>           <font isunderline="true"/>         </textelement>         <text><![cdata[count]]></text>       </statictext>     </band>   </columnheader>   <detail>     <band height="20">       <textfield>         <reportelement x="180" y="0" width="180" height="15"/>         <textelement/>         <textfieldexpression><![cdata[$f{field}]]></textfieldexpression>       </textfield>       <textfield>         <reportelement x="360" y="0" width="180" height="15"/>         <textelement/>         <textfieldexpression><![cdata[$f{count}]]></textfieldexpression>       </textfield>     </band>   </detail>   <columnfooter>     <band/>   </columnfooter>   <pagefooter>     <band height="15">       <statictext>         <reportelement x="0" y="0" width="40" height="15"/>         <textelement/>         <text><![cdata[page:]]></text>       </statictext>       <textfield>         <reportelement x="40" y="0" width="100" height="15"/>         <textelement/>         <textfieldexpression class="java.lang.integer"><![cdata[$v{page_number}]]></textfieldexpression>       </textfield>     </band>   </pagefooter>   <summary>     <band/>   </summary> </jasperreport> 

my input xmls

<response id="1074200577">     <results id1="0" id2="0">         <field count="7556">one</field>         <field count="7524">two</field>         <field count="7402">three</field>         <field count="7304">four</field>     </results> </response> 

my java client

jaspercompilemanager.compilereporttofile(inpuutjrxml, outputjasper); jrxmldatasource source = new jrxmldatasource(new file(sourcefile)); hashmap<string, object> params = new hashmap<string, object>(); jasperprint jasperprint = jasperfillmanager.fillreport(outputjasper, params, source); jasperexportmanager.exportreporttopdfstream(jasperprint, new fileoutputstream(pefoutput)); 

how values input xml?

also how id value ? first xml row <field count="7556">one</field>

<fielddescription><![cdata[//field[@count]]]></fielddescription> <fielddescription><![cdata[//field]]></fielddescription> 

gives same data "one"

you can try query (xpath):

/response/results/field 

and fields declaration:

<field name="field" class="java.lang.string">     <fielddescription><![cdata[child::text()]]></fielddescription> </field> <field name="count" class="java.lang.string">     <fielddescription><![cdata[@count]]></fielddescription> </field> 

using ireport

the full jrxml file trying ireport:

<?xml version="1.0" encoding="utf-8"?> <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="xml_missing_rows" language="groovy" pagewidth="595" pageheight="842" columnwidth="555" leftmargin="20" rightmargin="20" topmargin="20" bottommargin="20" uuid="09291847-62d6-4f2e-bf29-6db3230ce9a4">     <querystring language="xpath">         <![cdata[/response/results/field]]>     </querystring>     <field name="field" class="java.lang.string">         <fielddescription><![cdata[child::text()]]></fielddescription>     </field>     <field name="count" class="java.lang.string">         <fielddescription><![cdata[@count]]></fielddescription>     </field>     <detail>         <band height="20" splittype="stretch">             <textfield>                 <reportelement uuid="30be33c9-3e8c-4b8f-89b7-c2cdafd91615" x="0" y="0" width="100" height="20"/>                 <textelement/>                 <textfieldexpression><![cdata[$f{field}]]></textfieldexpression>             </textfield>             <textfield>                 <reportelement uuid="30be33c9-3e8c-4b8f-89b7-c2cdafd91615" x="100" y="0" width="100" height="20"/>                 <textelement/>                 <textfieldexpression><![cdata[$f{count}]]></textfieldexpression>             </textfield>         </band>     </detail> </jasperreport> 

the result input data (via preview in ireport):

the result in ireport


note:
i've used ireport 5.2.0

using java code

you should modify code as:

jrxmldatasource source = new jrxmldatasource(new file(sourcefile), "/response/results/field"); hashmap<string, object> params = new hashmap<string, object>(); jasperprint jasperprint = jasperfillmanager.fillreport(outputjasper, params, source); jasperexportmanager.exportreporttopdfstream(jasperprint, new fileoutputstream(pefoutput)); 

in case using jrxmldatasource(java.io.file file, java.lang.string selectexpression) constructor. passing query data.

the jrxml should be:

<?xml version="1.0" encoding="utf-8"?> <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="xmldssample" language="groovy" pagewidth="595" pageheight="842" columnwidth="555" leftmargin="20" rightmargin="20" topmargin="20" bottommargin="20" uuid="09291847-62d6-4f2e-bf29-6db3230ce9a4">     <field name="field" class="java.lang.string">         <fielddescription><![cdata[child::text()]]></fielddescription>     </field>     <field name="count" class="java.lang.string">         <fielddescription><![cdata[@count]]></fielddescription>     </field>     <detail>         <band height="20" splittype="stretch">             <textfield>                 <reportelement uuid="30be33c9-3e8c-4b8f-89b7-c2cdafd91615" x="0" y="0" width="100" height="20"/>                 <textelement/>                 <textfieldexpression><![cdata[$f{field}]]></textfieldexpression>             </textfield>             <textfield>                 <reportelement uuid="30be33c9-3e8c-4b8f-89b7-c2cdafd91615" x="100" y="0" width="100" height="20"/>                 <textelement/>                 <textfieldexpression><![cdata[$f{count}]]></textfieldexpression>             </textfield>         </band>     </detail> </jasperreport> 

as can see i've removed querystring template - passing query in java code.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -