I'm using Jaspersoft studio to create label. I'm using an XML file along with an XMLDataAdapter. Here is an example of my XML file
<records>
<record>
<metadatas>
<title>first title</title>
<description>descriptions</description>
<keywords />
<!-- ... -->
</metadatas>
</record>
</records>
The problem here is that I want to access the keywords fields, which can be set in some case or not, but when I try to read fields in the data adapter they do not show up.
Is there a configuration to change or somethings to I can compile my jasperreport.
There is no special setting you just not define your fields relative to the XPath query
In your example you probably like to loop on record so your XPath query will be
<queryString language="XPath">
<![CDATA[/records/record]]>
</queryString>
To define a field that points to keywords
you use the fieldDescription
<field name="keywords" class="java.lang.String">
<fieldDescription><![CDATA[metadatas/keywords]]></fieldDescription>
</field>
The name is arbitrary, the class is the representation of value in java and the fieldDescription is relative path to your node related to your queryString
In JasperSoft Studio this is achieved by first defining your data adapter, then right clicking report node, and select "Dataset and Query". In the dialog select your data adapter and XPath, then write your XPath query and click fields you like to add as fields
<?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>
As you will se it will show null
for nodes that do not have value, if you like to show empty text just set isBlankWhenNull="true"
on the relative textField