Jump to content
Changes to the Jaspersoft community edition download ×
  • Accessing nested repeated fields in your XML document


    emistry

    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.

    1(66).png.0998930ee63512bba0445705be5f2a9b.png


    Procedure

    1. Create a Datasource Adaptor

      1(67).png.ec5e713030f31e287501f6dba06b8b45.png

    2. Create a Report

      Create a report and at the Data Source stage choose the Data Adaptor you created earlier and use the parameter below.

      1(68).png.28c3dc666a15d2fb543089c914d5a4a9.png

      Select all the Fields in the next stage and then Finish.

      1(69).png.7f9ad880d672bb41b3ec3cd94f7a9988.png

      Move the fields over and delete the license number value field.

      1(70).png.363c1650fa2d16007b9393b2c8b30d55.png

    3. 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")
      

      1(71).png.744f286dc1e843a850a1811298aa2f0a.png

    4. Create a Field in the new Dataset (sub dataset)

      1(72).png.f49445f96d82b566cdff69d0e7ca68f9.png

      And in the description field of the new field add: child::text() , once complete drag the field into the list element on the report.

    5. Ready to preview now and as you can see below the nested fields are appearing as expected...

      1(73).png.aca3ce4e714ec96f70407794148f97ef.png


    Related Information

    1(70).png.9224c8c79a57ebc8d892d5ab2d4f45a5.png

    1(72).png.8490d285a88959f4949ca321d44ad8d2.png

    xml-nestedfields.xml


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...