Marsanka Geschrieben 11. August 2009 Teilen Geschrieben 11. August 2009 Hallo an alle, ich versuche eine Crosstabelle mit JasperReport zu erstellen. Der gleiche Report mit DB als datenQuelle habe ich schon ausprobiert und es hat funktioniert. Ich brauche aber die XML-Datei als Datenquelle. Den Report habe ich entsprechend angepasst. Leider funktioniert noch nicht. Folgender Fehler wird nun angezeigt: 11.08.2009 12:13:47 net.sf.jasperreports.engine.query.JRXPathQueryExecuter <init> WARNUNG: The supplied org.w3c.dom.Document object is null. Das bedeutet, dass der xPath in der XML-Datei anders sein sollte, weil die Daten nicht gefunden werden. Ich habe schon alles mögliche überprüft. Vielleicht hat jemand, der sich mit JasperReport auskennt, eine Idee, was falsch sein könnte? Hier bitte den Quellcode: import java.io.File; import java.util.HashMap; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.data.JRXmlDataSource; public class JasperReport_PDF { public JasperReport_PDF() { } public void erstellePDF() { JasperReport jasperReport; JasperPrint jasperPrint; HashMap<String, String> parameter = new HashMap<String, String>(); try { JRXmlDataSource xml = new JRXmlDataSource(new File("ShipmentsReport_XML.xml"), "/template51000/Orders"); jasperReport = JasperCompileManager.compileReport("ShipmentsReport_XML.jrxml"); jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, xml); JasperExportManager.exportReportToPdfFile(jasperPrint, "out/ShipmentsReport_XML.pdf"); } catch (JRException e) { e.printStackTrace(); } } public static void main(String[] args) { JasperReport_PDF pdf = new JasperReport_PDF(); pdf.erstellePDF(); System.out.println("PDF wurde erstellt!"); } } Hier der jrxml-Report: <?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="ShipmentsReport" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="812" leftMargin="15" rightMargin="15" topMargin="10" bottomMargin="10"> <style name="Arial_Normal" isDefault="true" fontName="Arial" fontSize="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> <style name="Arial_Bold" isDefault="false" fontName="Arial" fontSize="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/> <subDataset name="Country_Orders"> <parameter name="Country" class="java.lang.String" /> <queryString language="xPath"> <![CDATA[/template51000/Orders]]> </queryString> <field name="ShippedDate" class="java.sql.Timestamp"> <fieldDescription><![CDATA[ShippedDate]]></fieldDescription> </field> <field name="ShipRegion" class="java.lang.String"> <fieldDescription><![CDATA[ShipRegion]]></fieldDescription> </field> <field name="ShipCity" class="java.lang.String"> <fieldDescription><![CDATA[ShipCity]]></fieldDescription> </field> <field name="Freight" class="java.lang.Float"> <fieldDescription><![CDATA[Freight]]></fieldDescription> </field> </subDataset> <queryString language="xPath"> <![CDATA[/template51000/Orders]]> </queryString> <field name="ShipCountry" class="java.lang.String"> <fieldDescription><![CDATA[ShipCountry]]></fieldDescription> </field> <detail> <band height="100" splitType="Stretch"> <textField> <reportElement x="0" y="0" width="500" height="15"/> <textElement> <font fontName="Arial_Bold" size="10"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Shipments to " + $F{ShipCountry}]]></textFieldExpression> </textField> <crosstab isRepeatColumnHeaders="false"> <reportElement mode="Opaque" x="0" y="20" width="812" height="60"/> <crosstabParameter name="Country"> <parameterValueExpression><![CDATA[$F{ShipCountry}]]></parameterValueExpression> </crosstabParameter> <crosstabDataset> <dataset> <datasetRun subDataset="Country_Orders"> <datasetParameter name="Country"> <datasetParameterExpression><![CDATA[$F{ShipCountry}]]></datasetParameterExpression> </datasetParameter> </datasetRun> </dataset> </crosstabDataset> <rowGroup name="Region" width="50" totalPosition="End"> <bucket> <bucketExpression class="java.lang.String"><![CDATA[$F{ShipRegion}]]></bucketExpression> </bucket> <crosstabRowHeader> <cellContents> <box> <leftPen lineWidth="2.0" lineStyle="Solid"/> <bottomPen lineWidth="2.0" lineStyle="Solid"/> <rightPen lineWidth="2.0" lineStyle="Solid"/> </box> <textField> <reportElement x="5" y="5" width="40" height="40"/> <textElement/> <textFieldExpression class="java.lang.String"><![CDATA[$V{Region} == null ? "No region" : $V{Region}]]></textFieldExpression> </textField> </cellContents> </crosstabRowHeader> <crosstabTotalRowHeader> <cellContents backcolor="#60FFFF"> <box> <leftPen lineWidth="2.0" lineStyle="Solid"/> <bottomPen lineWidth="2.0" lineStyle="Solid"/> <rightPen lineWidth="2.0" lineStyle="Solid"/> </box> <textField> <reportElement x="5" y="5" width="110" height="20"/> <textElement/> <textFieldExpression class="java.lang.String"><![CDATA[$P{Country} + " Total"]]></textFieldExpression> </textField> </cellContents> </crosstabTotalRowHeader> </rowGroup> <rowGroup name="City" width="70" totalPosition="End"> <bucket> <bucketExpression class="java.lang.String">$F{ShipCity}</bucketExpression> </bucket> <crosstabRowHeader> <cellContents> <box bottomBorder="2Point" rightBorder="2Point"/> <textField> <reportElement x="5" y="5" width="60" height="15"/> <textFieldExpression>$V{City}</textFieldExpression> </textField> </cellContents> </crosstabRowHeader> <crosstabTotalRowHeader> <cellContents backcolor="#E0FFFF"> <box bottomBorder="2Point" rightBorder="2Point"/> <staticText> <reportElement x="5" y="5" width="60" height="15"/> <text>Total</text> </staticText> </cellContents> </crosstabTotalRowHeader> </rowGroup> <columnGroup name="ShipYear" height="30" totalPosition="End" headerPosition="Stretch"> <bucket> <bucketExpression class="java.sql.Timestamp"><![CDATA[$F{ShippedDate}]]></bucketExpression> </bucket> <crosstabColumnHeader> <cellContents> <box> <topPen lineWidth="2.0" lineStyle="Solid"/> <bottomPen lineWidth="2.0" lineStyle="Solid"/> <rightPen lineWidth="2.0" lineStyle="Solid"/> </box> <rectangle radius="10"> <reportElement x="4" y="4" width="52" height="22"/> <graphicElement> <pen lineWidth="1.0" lineStyle="Solid"/> </graphicElement> </rectangle> <textField pattern="yyyy"> <reportElement x="5" y="5" width="50" height="20"/> <textElement textAlignment="Center" verticalAlignment="Middle"/> <textFieldExpression class="java.sql.Timestamp"><![CDATA[$V{ShipYear}]]></textFieldExpression> </textField> </cellContents> </crosstabColumnHeader> <crosstabTotalColumnHeader> <cellContents backcolor="#FFFF60"> <box> <topPen lineWidth="2.0" lineStyle="Solid"/> <bottomPen lineWidth="2.0" lineStyle="Solid"/> <rightPen lineWidth="2.0" lineStyle="Solid"/> </box> <staticText> <reportElement x="5" y="5" width="20" height="15"/> <textElement/> <text><![CDATA[Total]]></text> </staticText> </cellContents> </crosstabTotalColumnHeader> </columnGroup> <columnGroup name="ShipMonth" height="40" totalPosition="End"> <bucket> <bucketExpression class="java.sql.Timestamp"><![CDATA[$F{ShippedDate}]]></bucketExpression> </bucket> <crosstabColumnHeader> <cellContents> <box> <bottomPen lineWidth="2.0" lineStyle="Solid"/> <rightPen lineWidth="2.0" lineStyle="Solid"/> </box> <textField pattern="MMM"> <reportElement x="5" y="5" width="20" height="30"/> <textElement/> <textFieldExpression class="java.sql.Timestamp"><![CDATA[$V{ShipMonth}]]></textFieldExpression> </textField> </cellContents> </crosstabColumnHeader> <crosstabTotalColumnHeader> <cellContents/> </crosstabTotalColumnHeader> </columnGroup> <measure name="FreightSum" class="java.lang.Float" calculation="Sum"> <measureExpression><![CDATA[$F{Freight}]]></measureExpression> </measure> <crosstabCell width="30" height="25"> <cellContents backcolor="#FFFFFF"> <box> <bottomPen lineWidth="1.0" lineStyle="Solid"/> <rightPen lineWidth="1.0" lineStyle="Solid"/> </box> <textField pattern="#0.0"> <reportElement x="0" y="0" width="25" height="25"/> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{FreightSum}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell width="30" height="25" columnTotalGroup="ShipMonth"> <cellContents backcolor="#FFFFC0"> <box> <bottomPen lineWidth="1.0" lineStyle="Solid"/> <rightPen lineWidth="1.0" lineStyle="Solid"/> </box> <textField pattern="#0.0"> <reportElement style="Arial_Bold" x="0" y="0" width="25" height="25"/> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{FreightSum}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell width="35" height="25" columnTotalGroup="ShipYear"> <cellContents backcolor="#FFFF60"> <box> <bottomPen lineWidth="1.0" lineStyle="Solid"/> <rightPen lineWidth="1.0" lineStyle="Solid"/> </box> <textField pattern="#0.0"> <reportElement style="Arial_Bold" x="0" y="0" width="30" height="25"/> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{FreightSum}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell height="25" rowTotalGroup="City"> <cellContents backcolor="#E0FFFF"> <box> <bottomPen lineWidth="1.0" lineStyle="Solid"/> <rightPen lineWidth="1.0" lineStyle="Solid"/> </box> <textField pattern="#0.0"> <reportElement x="0" y="0" width="25" height="25"/> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{FreightSum}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell rowTotalGroup="City" columnTotalGroup="ShipMonth"> <cellContents backcolor="#E0FFC0"> <box> <bottomPen lineWidth="1.0" lineStyle="Solid"/> <rightPen lineWidth="1.0" lineStyle="Solid"/> </box> <textField pattern="#0.0"> <reportElement style="Arial_Bold" x="0" y="0" width="25" height="25"/> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{FreightSum}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell rowTotalGroup="City" columnTotalGroup="ShipYear"> <cellContents backcolor="#E0FF60"> <box> <bottomPen lineWidth="1.0" lineStyle="Solid"/> <rightPen lineWidth="1.0" lineStyle="Solid"/> </box> <textField pattern="#0.0"> <reportElement style="Arial_Bold" x="0" y="0" width="30" height="25"/> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{FreightSum}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell height="30" rowTotalGroup="Region"> <cellContents backcolor="#60FFFF"> <box> <bottomPen lineWidth="1.0" lineStyle="Solid"/> <rightPen lineWidth="1.0" lineStyle="Solid"/> </box> <textField pattern="#0.0"> <reportElement style="Arial_Bold" x="0" y="0" width="25" height="30"/> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{FreightSum}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell rowTotalGroup="Region" columnTotalGroup="ShipMonth"> <cellContents backcolor="#60FFC0"> <box> <bottomPen lineWidth="1.0" lineStyle="Solid"/> <rightPen lineWidth="1.0" lineStyle="Solid"/> </box> <textField pattern="#0.0"> <reportElement style="Arial_Bold" x="0" y="0" width="25" height="30"/> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{FreightSum}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell rowTotalGroup="Region" columnTotalGroup="ShipYear"> <cellContents backcolor="#60FF60"> <box> <bottomPen lineWidth="1.0" lineStyle="Solid"/> <rightPen lineWidth="1.0" lineStyle="Solid"/> </box> <textField pattern="#0.0"> <reportElement style="Arial_Bold" x="0" y="0" width="30" height="30"/> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{FreightSum}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> </crosstab> </band> </detail> </jasperReport> Und nun die XML-Datei: <?xml version="1.0" encoding="UTF-8"?> <template51000> <Orders> <ShipCountry>Deuschland</ShipCountry> <ShippedDate>2009-08-05 21:41:45</ShippedDate> <ShipRegion>X</ShipRegion> <ShipCity>Berlin</ShipCity> <Freight>3.50</Freight> </Orders> <Orders> <ShipCountry>Deuschland</ShipCountry> <ShippedDate>2009-07-05 21:41:45</ShippedDate> <ShipRegion>X</ShipRegion> <ShipCity>Berlin</ShipCity> <Freight>4.50</Freight> </Orders> <Orders> <ShipCountry>Deuschland</ShipCountry> <ShippedDate>2009-06-05 21:41:45</ShippedDate> <ShipRegion>X</ShipRegion> <ShipCity>Berlin</ShipCity> <Freight>5.50</Freight> </Orders> <Orders> <ShipCountry>Deuschland</ShipCountry> <ShippedDate>2009-05-05 21:41:45</ShippedDate> <ShipRegion>X</ShipRegion> <ShipCity>Berlin</ShipCity> <Freight>6.50</Freight> </Orders> <Orders> <ShipCountry>Deuschland</ShipCountry> <ShippedDate>2009-04-05 21:41:45</ShippedDate> <ShipRegion>X</ShipRegion> <ShipCity>Berlin</ShipCity> <Freight>7.50</Freight> </Orders> <Orders> <ShipCountry>Deuschland</ShipCountry> <ShippedDate>2009-03-05 21:41:45</ShippedDate> <ShipRegion>X</ShipRegion> <ShipCity>Berlin</ShipCity> <Freight>8.50</Freight> </Orders> <Orders> <ShipCountry>Deuschland</ShipCountry> <ShippedDate>2009-02-05 21:41:45</ShippedDate> <ShipRegion>X</ShipRegion> <ShipCity>Berlin</ShipCity> <Freight>9.50</Freight> </Orders> </template51000> eim Ausführen werden nur Überschriften geholt, aber keine Tabelle :-( Kann mir jemand vielleicht helfen? Danke! Zitieren Link zu diesem Kommentar Auf anderen Seiten teilen Mehr Optionen zum Teilen...
Empfohlene Beiträge
Dein Kommentar
Du kannst jetzt schreiben und Dich später registrieren. Wenn Du ein Konto hast, melde Dich jetzt an, um unter Deinem Benutzernamen zu schreiben.