Discussion
In this example I will use this data for accessing repeated nested fields:
<root> <outputDocument> <driver> <driverName>Nick Butler *</driverName> <driverLicence> <licenceNumber>CK17683 (16-08-2031)</licenceNumber> <licenceNumber>XX14536 (21-10-2036)</licenceNumber> </driverLicence> <driverDoB>14-01-1970</driverDoB> <passportNumber>PP3462748 (22-07-2016)</passportNumber> <visaNumber>VT57383212 (21-09-2014)</visaNumber> </driver> <driver> <driverName>James Marmeduke</driverName> <driverLicence> <licenceNumber>MES16584 (16-08-2030)</licenceNumber> </driverLicence> <driverDoB>01-12-1962</driverDoB> <passportNumber></passportNumber> <visaNumber></visaNumber> </driver> </outputDocument> </root>
(Data File attached below)
The highlighted data, below, though, is not intuitive to extract and therefore I have created this little WIKI page to remind me how to do it.
Procedure
Create a Datasource Adaptor
Create a Report
Create a report and at the Data Source stage choose the Data Adaptor you created earlier and use the parameter below.
Select all the Fields in the next stage and then Finish.
Move the fields over and delete the license number value field.
Create a list element, pull over a List element .. into the space for the License Number value ..
“Create a list using a new dataset” -> “Create an empty dataset” -> “Use a JRDatasource expression” and in the expression add :
((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/driver/driverLicence/licenceNumber")
Create a Field in the new Dataset (sub dataset)
And in the description field of the new field add: child::text() , once complete drag the field into the list element on the report.
Ready to preview now and as you can see below the nested fields are appearing as expected...
Related Information
- http://youtu.be/iayX5W61qwk - Short Video containing "How to do it .. "
Recommended Comments
There are no comments to display.