0

我尝试在iReport上使用XML,所以我阅读了一个教程

但是当我编译报告时,我得到了这个错误:

Error filling print... XPath compilation failed. Expression:  

net.sf.jasperreports.engine.JRException: XPath compilation failed. Expression:  
at net.sf.jasperreports.engine.util.xml.JaxenXPathExecuter.getXPath JaxenXPathExecuter.java:66)      
at net.sf.jasperreports.engine.util.xml.JaxenXPathExecuter.selectNodeList(JaxenXPathExecuter.java:77)      
at net.sf.jasperreports.engine.data.JRXmlDataSource.moveFirst(JRXmlDataSource.java:415) 
at net.sf.jasperreports.engine.data.JRXmlDataSource.<init>(JRXmlDataSource.java:189) 
at net.sf.jasperreports.engine.query.JRXPathQueryExecuter.createDatasource(JRXPathQueryExecuter.java:113)
at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1087)  
at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:668)  
at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1258)  
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:877)  
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:126)  
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:464)  
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:300)  
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:757)  
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:1003) 
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) 
Caused by: org.jaxen.XPathSyntaxException: Unexpected ''      
at org.jaxen.BaseXPath.<init>(BaseXPath.java:118)      
at org.jaxen.BaseXPath.<init>(BaseXPath.java:139)      
at org.jaxen.dom.DOMXPath.<init>(DOMXPath.java:87) 
at net.sf.jasperreports.engine.util.xml.JaxenXPathExecuter.getXPath(JaxenXPathExecuter.java:62)     
 ... 15 more  
Caused by: class org.jaxen.saxpath.XPathSyntaxException: : 0: Unexpected ''  
at org.jaxen.saxpath.base.XPathReader.createSyntaxException(XPathReader.java:1084)  
at org.jaxen.saxpath.base.XPathReader.pathExpr(XPathReader.java:190)  
at org.jaxen.saxpath.base.XPathReader.unionExpr(XPathReader.java:1006)  
at org.jaxen.saxpath.base.XPathReader.unaryExpr(XPathReader.java:994)  
at org.jaxen.saxpath.base.XPathReader.multiplicativeExpr(XPathReader.java:943) 
at org.jaxen.saxpath.base.XPathReader.additiveExpr(XPathReader.java:913)  
at org.jaxen.saxpath.base.XPathReader.relationalExpr(XPathReader.java:860)  
at org.jaxen.saxpath.base.XPathReader.equalityExpr(XPathReader.java:829)  
at org.jaxen.saxpath.base.XPathReader.andExpr(XPathReader.java:809)  
at org.jaxen.saxpath.base.XPathReader.orExpr(XPathReader.java:787) 
at org.jaxen.saxpath.base.XPathReader.expr(XPathReader.java:780)  
at org.jaxen.saxpath.base.XPathReader.parse(XPathReader.java:100)      
at org.jaxen.BaseXPath.<init>(BaseXPath.java:113)      ... 18 more  
Print not filled. Try to use an EmptyDataSource...

XML是:

<palette>
    <color>Red</color>
    <color>Green</color>
    <color>Blue</color>
</palette>

我的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="report" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a7fd885b-4cc6-40a2-a2e1-94538a942473">
    <queryString language="xPath">
        <![CDATA[]]>
    </queryString>
    <field name="color" class="java.lang.String">
        <fieldDescription><![CDATA[/palette/color]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <staticText>
                <reportElement uuid="4d48ae42-2bf9-4b84-ba00-d55024428772" x="91" y="2" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[/palette/color]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement uuid="e812c9c3-9aaa-4376-8a67-8ae386eaba13" x="91" y="51" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{color}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

有人可以解释一下发生了什么吗?

4

2 回答 2

0

使用 /palette/color 作为查询字符串,并将字段描述更改为 text() 或 "." (删除引号)。

于 2013-06-12T15:26:49.560 回答
-1

XML 从

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

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

..是的,仅此而已,我需要 2 天时间才能解决您遇到的相同问题-.-

于 2017-02-03T16:06:58.297 回答