Successfully!

Error!

TXT and XML Dataset

  • Last update:  2020-12-02
  • I. Overview

    1) Some data are stored in unstructured or semi-structured forms, including TXT and XML files. 

    2) This article takes a local file as an example to create TXT and XML datasets.

    You will learn
    • TXT dataset

    • XML dataset

    II. Text dataset

    1. Create a TXT file

    1) Create a new file named datasource.txt in webapps\webroot\WEB-INR\reportlets under the FineReport installation directory.

    2) Save the following contents into the file:

    Name,Capital,Continent,Area,Population    
    Argentina,Buenos Aires,South America,2777815.00,32300003.00  
    Bolivia,La Paz,South America,1098575.00,7300000.00    
    Brazil,Brasilia,South America,8511196.00,150400000.00    
    Canada,Ottawa,North America,9976147.00,26500000.00    
    Chile,Santiago,South America,756943.00,13200000.00    
    Colombia,Bagota,South America,1138907.00,33000000.00    
    Cuba,Havana,North America,114524.00,10600000.00    
    Ecuador,Quito,South America,455502.00,10600000.00    
    El Salvador,San Salvador,North America,20865.00,5300000.00    
    Guyana,Georgetown,South America,214969.00,800000.00    
    Jamaica,Kingston,North America,11424.00,2500000.00    
    Mexico,Mexico City,North America,1967180.00,88600000.00    
    Nicaragua,Managua,North America,139000.00,3900000.00    
    Paraguay,Asuncion,South America,406576.00,4660000.00    
    Peru,Lima,South America,1285215.00,21600000.00    
    United States of America,Washington,North America,9363130.00,249200000.00    
    Uruguay,Montevideo,South America,176140.00,3002000.00    
    Venezuela,Caracas,South America,912047.00,19700000.00

     


    2. Click [+] and select [File]


    3. Dataset setting

    1) File Type: TXT.

    2) File Address: Click Selection and select datasource.txt.

    3) Check First row contains column headings.

    4) Separator:Comma.


    4. Preview the dataset


    5. The generated dataset has five data columns, corresponding to the first row of the TXT file


    6. Modify the contents of datasource.txt as there is a null value in the first row

    Name,Capital,Continent,Area,Population    
    Argentina,Buenos Aires,,,32300003.00
    Bolivia,La Paz,South America,1098575.00,7300000.00    
    Brazil,Brasilia,South America,8511196.00,150400000.00    
    Canada,Ottawa,North America,9976147.00,26500000.00    
    Chile,Santiago,South America,756943.00,13200000.00    
    Colombia,Bagota,South America,1138907.00,33000000.00    
    Cuba,Havana,North America,114524.00,10600000.00    
    Ecuador,Quito,South America,455502.00,10600000.00    
    El Salvador,San Salvador,North America,20865.00,5300000.00    
    Guyana,Georgetown,South America,214969.00,800000.00    
    Jamaica,Kingston,North America,11424.00,2500000.00    
    Mexico,Mexico City,North America,1967180.00,88600000.00    
    Nicaragua,Managua,North America,139000.00,3900000.00    
    Paraguay,Asuncion,South America,406576.00,4660000.00    
    Peru,Lima,South America,1285215.00,21600000.00    
    United States of America,Washington,North America,9363130.00,249200000.00    
    Uruguay,Montevideo,South America,176140.00,3002000.00    
    Venezuela,Caracas,South America,912047.00,19700000.00

    7. Dataset setting

    1) Uncheck Regard consecutive separators as one.

    2) Preview. The null value in the first row is recognized.


    8. Other options

    1) Parameter: Used to dynamically switch between different TXT files during preview. Reference for setting mode: Excel Dataset.

    2) Encoding: Set encoding type according to the encoding of the source file. It supports such encoding types as GBK, ISO-8859-1, UTF-8, UTF-16, EUC_JP, EUC_KR and CP850.

    III. XML dataset

    1. Create XML files

    1) Create a new file named frtest.xml in webapps\webroot\WEB-INR\reportlets under the FineReport installation directory.

    2) Save the following contents into the file:

    <?xml version="1.0" encoding="UTF-8"?>
    <frtest>
        <Customers>
            <Name>ALFKI</Name>
            <type>ALfreds Futterkiste</type>
            <value>90</value>
        </Customers>
        <Customers>
            <Name>ANATR</Name>
            <type>Ana Trujillo Emparedados y helados</type>
            <value>90</value>
        </Customers>
    </frtest>


    2. Click [+]and select [File]


    3. Dataset configuration

    1) File Type: XML.

    2) Local File: Click Selection and select frtest.xml.

    3) DOM structure of XML file is displayed on the right of the file setting panel.


    4. Preview the dataset


    5. The generated dataset has three data columns, corresponding to the leaf nodes of XML file


    6. Other options

    1) Parameter: Used to dynamically switch between different XML files during preview. Reference for setting mode: Excel Dataset.

    2) Encoding: Set encoding type according to the encoding of the source file. It supports such encoding types as GBK, ISO-8859-1, UTF-8, UTF-16, EUC_JP, EUC_KR and CP850.


    Attachment List


    Theme: Data Preparation
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    Doc Feedback