没有特殊设置,您只是没有定义相对于 XPath 查询的字段
在您的示例中,您可能希望循环记录以便您的 XPath 查询将是
<queryString language="XPath">
<![CDATA[/records/record]]>
</queryString>
要定义指向keywords 的字段,请使用fieldDescription
<field name="keywords" class="java.lang.String">
<fieldDescription><![CDATA[metadatas/keywords]]></fieldDescription>
</field>
名称是任意的,类是java中值的表示,fieldDescription是与你的queryString相关的节点的相对路径
JasperSoft 工作室
在 JasperSoft Studio 中,这是通过首先defining your data adapter,然后右键单击报告节点并选择“数据集和查询”来实现的。在对话框中选择您的数据适配器和 XPath,然后编写您的 XPath 查询并单击要添加为字段的字段
完整的 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="XMLTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b487729d-4510-4485-b838-19c491042208">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="XMLTest"/>
<queryString language="XPath">
<![CDATA[/records/record]]>
</queryString>
<field name="title" class="java.lang.String">
<fieldDescription><![CDATA[metadatas/title]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[metadatas/description]]></fieldDescription>
</field>
<field name="keywords" class="java.lang.String">
<fieldDescription><![CDATA[metadatas/keywords]]></fieldDescription>
</field>
<columnHeader>
<band height="20" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<staticText>
<reportElement x="0" y="0" width="170" height="20" uuid="3ce3004b-8324-4f57-ba9f-77cdffc711da"/>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[title]]></text>
</staticText>
<staticText>
<reportElement x="170" y="0" width="170" height="20" uuid="6ee7c571-ecdc-45cc-b11d-600099121301"/>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[description]]></text>
</staticText>
<staticText>
<reportElement x="340" y="0" width="210" height="20" uuid="111fa52f-bc0b-4698-8ba9-a7af03988254"/>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[keywords]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="170" height="20" uuid="444010e8-18ce-4594-a1b1-ca3d120b091d"/>
<textElement verticalAlignment="Middle">
<font isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{title}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="170" y="0" width="170" height="20" uuid="9a27a707-c5df-4905-ac21-e42b21c1d77c"/>
<textElement verticalAlignment="Middle">
<font isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="340" y="0" width="210" height="20" uuid="1621de6d-7200-49aa-a0d4-56f64fec1b91"/>
<textElement verticalAlignment="Middle">
<font isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{keywords}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
示例数据源
<records>
<record>
<metadatas>
<title>first title</title>
<description>descriptions</description>
<keywords />
</metadatas>
</record>
<record>
<metadatas>
<title>second title</title>
<description>descriptions 2</description>
<keywords>test, hello</keywords>
</metadatas>
</record>
</records><records>
<record>
<metadatas>
<title>first title</title>
<description>descriptions</description>
<keywords />
</metadatas>
</record>
<record>
<metadatas>
<title>second title</title>
<description>descriptions 2</description>
<keywords>test, hello</keywords>
</metadatas>
</record>
</records>
输出
如您所见,它将为没有值的节点显示null,如果您想显示空文本,只需在相对textField 上设置isBlankWhenNull="true"