Jasper reports 使用XmlDataSource在iReports中创建表

Jasper reports 使用XmlDataSource在iReports中创建表,jasper-reports,Jasper Reports,我试图使用XmlDataSource创建一个表,但它既不打印表结构,也不显示数据。我正在使用iReport4.7.1。请帮忙 我所做的是: 创建了一个新的空白报告 创建了一个xml数据源 选择/发送详细信息/结果作为记录节点 创建了包含选定字段的表 下面是我正在使用的.jrxml文件: <?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.

我试图使用XmlDataSource创建一个表,但它既不打印表结构,也不显示数据。我正在使用iReport4.7.1。请帮忙

我所做的是:

  • 创建了一个新的空白报告
  • 创建了一个xml数据源
  • 选择/发送详细信息/结果作为记录节点
  • 创建了包含选定字段的表
  • 下面是我正在使用的.jrxml文件:

        <?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="testReport2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a19f4e39-052a-483f-834a-5546d7626590">
        <property name="ireport.zoom" value="1.5"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <style name="table">
            <box>
                <pen lineWidth="1.0" lineColor="#000000"/>
            </box>
        </style>
        <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
            </box>
            <conditionalStyle>
                <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
                <style backcolor="#EFF7FF"/>
            </conditionalStyle>
        </style>
        <style name="table 1">
            <box>
                <pen lineWidth="1.0" lineColor="#000000"/>
            </box>
        </style>
        <style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
            </box>
            <conditionalStyle>
                <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
                <style backcolor="#EFF7FF"/>
            </conditionalStyle>
        </style>
        <subDataset name="Dataset" uuid="601a324d-5c44-4688-b6d4-cf64b3869ba4">
            <queryString language="xPath">
                <![CDATA[/sendDetail/results]]>
            </queryString>
            <field name="results" class="java.lang.String">
                <fieldDescription><![CDATA[child::text()]]></fieldDescription>
            </field>
            <field name="effDate" class="java.lang.String">
                <fieldDescription><![CDATA[effDate]]></fieldDescription>
            </field>
            <field name="period" class="java.lang.String">
                <fieldDescription><![CDATA[period]]></fieldDescription>
            </field>
            <field name="amount" class="java.lang.String">
                <fieldDescription><![CDATA[amount]]></fieldDescription>
            </field>
            <field name="totalAmount" class="java.lang.String">
                <fieldDescription><![CDATA[totalAmount]]></fieldDescription>
            </field>
            <field name="description" class="java.lang.String">
                <fieldDescription><![CDATA[description]]></fieldDescription>
            </field>
        </subDataset>
        <queryString language="xPath">
            <![CDATA[/sendDetail/results]]>
        </queryString>
        <field name="effDate" class="java.lang.String">
            <fieldDescription><![CDATA[effDate]]></fieldDescription>
        </field>
        <field name="period" class="java.lang.String">
            <fieldDescription><![CDATA[period]]></fieldDescription>
        </field>
        <field name="amount" class="java.lang.String">
            <fieldDescription><![CDATA[amount]]></fieldDescription>
        </field>
        <field name="totalAmount" class="java.lang.String">
            <fieldDescription><![CDATA[totalAmount]]></fieldDescription>
        </field>
        <field name="description" class="java.lang.String">
            <fieldDescription><![CDATA[description]]></fieldDescription>
        </field>
        <background>
            <band splitType="Stretch"/>
        </background>
        <detail>
            <band height="65" splitType="Stretch">
                <componentElement>
                    <reportElement uuid="9bed609a-a1cf-489d-a7b0-d322f0dfc9db" key="table 1" style="table 1" x="0" y="0" width="555" height="65"/>
                    <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                        <datasetRun subDataset="Dataset" uuid="33620359-7c04-4c08-9f6c-a18d9c5eb044">
                            <connectionExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_CONNECTION}).subDataSource("/sendDetail/results")]]></connectionExpression>
                        </datasetRun>
                        <jr:column uuid="9403d18c-6eec-447b-b8d2-c4973350060a" width="90">
                            <jr:columnHeader style="table 1_CH" height="30">
                                <staticText>
                                    <reportElement uuid="b86bb6ed-aee3-40b0-976e-bc4c23408910" x="0" y="0" width="90" height="30"/>
                                    <textElement/>
                                    <text><![CDATA[effDate]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="table 1_TD" height="20">
                                <textField>
                                    <reportElement uuid="de8b3535-74da-41b4-9f1d-7b66164bb0dc" x="0" y="0" width="90" height="20"/>
                                    <textElement/>
                                    <textFieldExpression><![CDATA[$F{effDate}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column uuid="ee9a667a-8916-4d87-87b7-e256e90e7682" width="90">
                            <jr:columnHeader style="table 1_CH" height="30">
                                <staticText>
                                    <reportElement uuid="3d173f1a-776d-415b-b241-ba4b4416a829" x="0" y="0" width="90" height="30"/>
                                    <textElement/>
                                    <text><![CDATA[period]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="table 1_TD" height="20">
                                <textField>
                                    <reportElement uuid="9d6db0e4-6b13-4af3-9060-9057246e4e63" x="0" y="0" width="90" height="20"/>
                                    <textElement/>
                                    <textFieldExpression><![CDATA[$F{period}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column uuid="d178a594-0faf-4a05-969c-2e17e65e9121" width="90">
                            <jr:columnHeader style="table 1_CH" height="30">
                                <staticText>
                                    <reportElement uuid="41a37b97-55be-45cb-8279-354d460ded19" x="0" y="0" width="90" height="30"/>
                                    <textElement/>
                                    <text><![CDATA[amount]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="table 1_TD" height="20">
                                <textField>
                                    <reportElement uuid="9e7714bc-3f8b-4d1e-8f77-ab8e9b14617f" x="0" y="0" width="90" height="20"/>
                                    <textElement/>
                                    <textFieldExpression><![CDATA[$F{amount}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column uuid="e2cdad6a-fd55-4b35-9fc9-c6c93f8d3c0e" width="90">
                            <jr:columnHeader style="table 1_CH" height="30">
                                <staticText>
                                    <reportElement uuid="b2d16a10-e73a-404d-8435-445664399482" x="0" y="0" width="90" height="30"/>
                                    <textElement/>
                                    <text><![CDATA[totalAmount]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="table 1_TD" height="20">
                                <textField>
                                    <reportElement uuid="ea85d3b8-23e4-4c24-a611-d099b4a6d242" x="0" y="0" width="90" height="20"/>
                                    <textElement/>
                                    <textFieldExpression><![CDATA[$F{totalAmount}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column uuid="e4a14c01-5159-41e2-b8eb-5fa333c8cc6c" width="90">
                            <jr:columnHeader style="table 1_CH" height="30">
                                <staticText>
                                    <reportElement uuid="0beaa2b0-6b2c-46d5-97ff-36a1888bd7b8" x="0" y="0" width="90" height="30"/>
                                    <textElement/>
                                    <text><![CDATA[description]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="table 1_TD" height="20">
                                <textField>
                                    <reportElement uuid="9b34870c-6013-47b5-af29-3380fbda1b25" x="0" y="0" width="90" height="20"/>
                                    <textElement/>
                                    <textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                    </jr:table>
                </componentElement>
            </band>
        </detail>
    </jasperReport>
    
    
    
    以下是xml文件:

    <sendDetail>    
    <results>
        <effDate>2015-10-20</effDate>
        <period>DEC 1;2015 TO FEB 29;2016</period>
        <amount>177.48</amount>
        <totalAmount>177.48</totalAmount>
        <description>Premium</description>
    </results>
    <results>
        <effDate>2015-10-20</effDate>
        <period>DEC 1;2015 TO FEB 29;2016</period>
        <amount>-177.48</amount>
        <totalAmount>0</totalAmount>
        <description>Premium Cancellation</description>
    </results>
    <results>
        <effDate>2015-07-20</effDate>
        <period>SEP 1;2015 TO NOV 30;2015</period>
        <amount>-177.48</amount>
        <totalAmount>0</totalAmount>
        <description>Premium Cancellation</description>
    </results>
    <results>
        <effDate>2015-07-20</effDate>
        <period>SEP 1;2015 TO NOV 30;2015</period>
        <amount>177.48</amount>
        <totalAmount>177.48</totalAmount>
        <description>Premium</description>
    </results>
    </sendDetail>
    
    
    2015-10-20
    12月1日;2015年至2月29日;2016
    177.48
    177.48
    保险费
    2015-10-20
    12月1日;2015年至2月29日;2016
    -177.48
    0
    保费取消
    2015-07-20
    9月1日;2015年至11月30日;2015
    -177.48
    0
    保费取消
    2015-07-20
    9月1日;2015年至11月30日;2015
    177.48
    177.48
    保险费
    
    您需要:

  • 将主数据集的
    queryString
    更改为:

    <queryString language="xPath">
        <![CDATA[/]]>
    </queryString>
    
  • <datasetRun subDataset="Dataset" uuid="33620359-7c04-4c08-9f6c-a18d9c5eb044">
        <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/sendDetail/results")]]></dataSourceExpression>
    </datasetRun>