XML Dataset

  • Last update:  2023-12-01
  • Overview

    XML datasets refer to those whose data source is a series of XML files. You can use FineReport to present data and perform data analysis with these files as data sources.

    Create a file frtest.xml in the path %FR_HOME%\webroot\WEB-INF\reportlets. The following figure and codes show the file content.

    1.png

    <?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>

    iconNote:
    To use an existing XML file as a dataset, you need to copy the corresponding file to the path %FR_HOME%\webapps\webroot\WEB-INF\reportlets.

    Defining an XML Dataset

    The following sections introduce how to define an XML dataset.

    Click the + icon above Template Dataset and select File Dataset from the drop-down list, as shown in the following figure.

     2.png

    Selecting an XML File

    Set File Type to XML in the file dataset popup box. Select Local File in the File Address area and click Selection to upload the existing frtest.xml file. The Key Node panel on the right is automatically refreshed to obtain all nodes in the XML file and displays the nodes in a tree structure, as shown in the following figure.

    3.png

    iconNote:
    If a node has multiple same-level child nodes with same names but different leaf nodes (namely nodes storing data) in each child node, the system takes the union of the leaf nodes as the dataset structure, as shown in the following figure. For example, the node bookstore has multiple same-level child nodes named book whose leaf nodes are not totally same. The first book node has two leaf nodes author and title and the second book node has two leaf nodes author and price. When you create an XML dataset, the union of all leaf nodes is displayed in the bottom-level leaf node of the tree structure on the Key Node panel.

     4.png

    If the XML dataset has two root nodes, FineReport automatically adds an unnamed empty root node at the top.

    <?xml version="1.0" encoding="UTF-8"?>
    <bookstore>
        <book>
        <author>J K.Rowing</author>
    <title>HMWHERE</title>
    <author>J K.Rowing</author>
    <author>J K.Rowing</author>
    </book>
        <book>
        <author>J K.Rowing</author>
    <author>J K.Rowing</author>
    <author>J K.Rowing</author>
    <price>19</price>
    </book>
    </bookstore>


    Selecting Nodes

    The XML dataset allows all nodes in the file to be displayed in a tree structure. Different from storage processes that return multiple result sets and display each node's data in a dataset, the XML dataset only returns all data from one selected child node at a time. That is, the data ultimately displayed comes from the subordinate nodes (including child nodes and their leaf nodes) of the selected node.

    <?xml version="1.0" encoding="GBK"?>
    <PickBillPrintEntity>
        <modifyTime>2013-08-11</modifyTime>
    <exprossCode>STO</exprossCode>
    <expressName>A Express</expressName>
        <pickDetail>
      <PrintPickDetailEntity>
        <address>3746  Concord Street, Charlotte, North Carolina</address>
    <city>Charlotte</city>
    <contactName>Alice</contactName>
    <deliveryOrderNo>668267627204339729</deliveryOrderNo>
    <district>Charlotte</district>
    <prov>NorthCarolina</prov>
    <qty>1.0</qty>
      </PrintPickDetailEntity>
      <PrintPickDetailEntity>
        <address>3746  Concord Street, Charlotte, North Carolina</address>
    <city>Charlotte</city>
    <contactName>Alice</contactName>
    <deliveryOrderNo>668267627204339729</deliveryOrderNo>
    <district>Charlotte</district>
    <prov>North Carolina</prov>
    <qty>2.0</qty>
      </PrintPickDetailEntity>
        </pickDetail>
    <packDetail>
      <PrintPackEntity>
        <baocai>SJZX*1</baocai>
    <itemCode>694852470667309</itemCode>
    <goodDese>Telephone</goodDese>
    <marksNumber>220cm*240cm</marksNumber>
    <qty>1.0</qty>
    <orderCount>1.0</orderCount>
    <skuCount>1.0</skuCount>
      </PrintPackEntity>
      <PrintPackEntity>
        <baocai>SJZX*1</baocai>
    <itemCode>694852471667309</itemCode>
    <goodDese>Computer</goodDese>
    <marksNumber>220cm*240cm</marksNumber>
    <qty>1.0</qty>
    <orderCount>1.0</orderCount>
    <skuCount>1.0</skuCount>
      </PrintPackEntity>
      <PrintPackEntity>
        <baocai>SJZX*1</baocai>
    <itemCode>694852472667309</itemCode>
    <goodDese>Victoria</goodDese>
    <marksNumber>200cm*230cm</marksNumber>
    <qty>2.0</qty>
    <orderCount>1.0</orderCount>
    <skuCount>2.0</skuCount>
      </PrintPackEntity>
      <other>
        <otherNo>1</otherNo>
      </other>
        </packDetail>
    </PickBillPrintEntity>

    Data returned to the XML dataset complies with following five rules:

    • If the selected node has only leaf nodes, the system takes the union of the leaf nodes as dataset fields.

     5.png

    If the selected node has only one child node (non-leaf node), the system takes the leaf nodes of this child node as dataset fields. For example, the node PickDetail has only one child node PrintPickDetailEntity. The data display effect when you select PickDetail is the same as that when you select PrintPickDetailEntity.

     6.png

    • If the selected node has multiple child nodes (non-leaf nodes), the system takes the leaf nodes of the first child node as dataset fields. For example, if you select the node packDetail that has multiple child nodes (PrintPackEntity and other), the system takes the leaf nodes of the first child node PrintPackEntity as dataset fields.

     7.png

    • If the selected node has both leaf nodes and regular child nodes (non-leaf nodes), namely, one-to-many relationship where the leaf nodes are "one" and the leaf nodes of the regular child nodes are "many", the system takes all leaf nodes and the leaf nodes of the first child node as dataset fields. The data content is displayed as follows: "One" is expanded as "many". For example, if you select the root node PickBillPrintEntity that has three leaf nodes and two child nodes (pickDetail and packDetail), the system takes the three leaf nodes and the leaf nodes of the first child node pickDetail as dataset fields.

     8.png

    • If a leaf node has multiple values, you can separate them with semicolons (;). For example, the values of the author field are James McGovern;Per Bothner;Kurt Cagle;James Linn;Vaidyanathan Nagaraian.

    9.png

    iconNote:
    You must select a node. Otherwise no data is displayed after you click Preview.

    For example, the parent node frtest only has one child node Customers. The returned result is the same whether you select the parent node, the child node, or the leaf nodes. Take the child node Customers as an example and click Preview, as shown in the following figure.

     10.png

    Effect Display

    After completion, a dataset named File1 is added to Template Dataset, as shown in the following figure.

     11.png

    Dynamic XML Dataset

    The configuration step is the same as Excel Dataset.

    Remote XML Dataset

    You can create remote XML datasets through two ways.

    • Through JSP to call XML files. The implementation method is the same as Remote Excel Dataset.

    • Through URL to directly call XML files.

    The following sections introduce how to directly call XML files through URL.

    Directly Calling XML Files Through URL

    You can enter http://IP address: Port number/App name/File name.xml in URL to directly call an XML file.

    iconNote:
     Name the XML file in English. Otherwise, the connection will fail.

    For example, if the frtest.xml file used in the above example is located in the WebReport project directory in the Tomcat environment, you can enter http://localhost:8075/WebReport/frtest.xml in URL, as shown in the following figure.

     12.png

    Click the refresh icon on the Key Node panel to obtain data from the XML file and select the needed nodes with the same rule as the local XML file.

    Notes

    Characters with Unicode decimal encoding values as 183, 215, and 247 (namely, the characters "·", "×",and "÷") are not supported. If you use these values, the XML dataset will fail to be loaded.

    Solution: Delete the three characters from the XML file, or wrap them as <![CDATA[xxx]]>.


    Attachment List


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

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy