|#1 Ranking: Read how InetSoft was rated #1 for user adoption in G2's user survey-based index
With the explosive growth of the Internet, a number of new data format standards have emerged. A widely accepted format is XML. With its self-descriptive properties, and both human and machine-readable format, XML has transformed the way information is exchanged.
The Data Modeler uses ‘XQuery’, (a standard developed by W3C) for querying XML documents and other forms of hierarchical data. It transforms the hierarchy into a flat tabular format to make it more conducive to reporting and analysis. The conditional expression syntax is based on SQL and is very easy to learn. This chapter provides a few examples of creating XML queries.
Define an XML Data Source
The creation of an XML data source in the Data Modeler is similar to the creation of a JDBC data source.
Select the ‘New Data Source’ button to create a new data source. Enter “MyPersonnel” for the data source name and select ‘xml’ as the data source type.
Read why choosing InetSoft's cloud-flexible BI
provides advantages over other BI options.
An XML data source can get its data from any URL. In particular, it can communicate with an HTTP server using the POST or GET methods to pass parameters to the server side program. Defining an XML data source requires specifying the URL and the optional parameters for the GET or POST methods. In addition, the DTD or XML schema must be specified for the XML data stream. It is possible to use a variable in the URL field, e.g., ‘file:///c:/datafiles/$(filename)’.
1 Enter the data source URL, which is “file:///$INSTALL_DIR$/ examples/docExamples/datasource/data/personnel.xml” in this example.
2 Select the HTTP method. If the URL does not use HTTP, select the GET method.
3 Click ‘Next>>’. Enter the name and the encoding of the request, “default” and “UTF8”. Each request is bound to a pre-defined XML output type (DTD). More requests can be added after the data source has been created. A request corresponds to a particular set of parameters in the data source server. For example, a servlet may expect a ‘file’ parameter which contains the file name of the XML file on the server.
4 Click ‘Next>>’. The parameter pane shows the current parameters for the request. For HTTP requests, the parameters are ordered in a parameter tree. The root of the tree is a ‘Parameters’ node. The child of the root is a sequence node, with one or more pairs of parameters. Each pair consists of a name and a value node. The name node contains the name of the HTTP request parameter, and the value node contains the value of the parameter.
To add a new parameter, select the ‘parameters’ node and click on the ‘Add’ button to the right of the parameter tree. You can now enter the name of the parameter and its value. You can continue to add more parameters using the ‘Add’ button. Check the variable box if you want the parameter value to be a variable.
5. Click on ‘Next>>’. Select ‘Browse’ and choose the DTD or XSD file that corresponds to the XML file (In the example, there is a personnel.dtd file). Click ‘Import DTD’.
6. Click ‘Finish’, then select the Output tab. The output tree shows the XML schema defined in the DTD file. Because the DTD format does not specify the real type of the data in the XML elements, all elements are treated as strings by default. The element type can be overridden by specifying the type for each element.
7. Expand the ‘employee’ node, select the ‘birthday’ node, and change its type to ‘date’.
8. Select the ‘salary’ node on the tree, and change its type to ‘double’.
9. ‘Save’ the data source.
“Flexible product with great training and support. The product has been very useful for quickly creating dashboards and data views. Support and training has always been available to us and quick to respond.
- George R, Information Technology Specialist at Sonepar USA
The data source URL can be dynamically specified by replacing the URL with a parameter, e.g., $(filename), when creating a new XML data source. The value for this ‘filename’ parameter can be specified using script or the programming API, just like with any other report parameters. If the parameter value is not provided to the report engine via script or the programming API, then the user will be prompted for it.
Every XML data source must contain at least one request. For more complex XML data sources, it is often necessary to create multiple requests. Each request can have different parameters and a different XML output type. If the URL is not HTTP based or does not need to have any parameters, simply create a request without specifying any parameters.