Klipfolio. The KPI Dashboard - Evolved
The KPI Dashboard – Evolved
1-877-233-6149
Contact Us

Extracting data from inside an XML tag

Problem:

The data you want to extract from the XML data source is inside the XML tag itself.

Solution:

Your XML data can be a bit more complex than a simple combination of nested tags. In the following example, the <Sales> tag makes up an item and also contains information we want to extract:

<html>

<Sales ProductName="Strings" ProductID="101" ProductColor="red" OrderQty="200" 
RepName="Peter" OrderDate="2009-08-18" />
<Sales ProductName="Yarn" ProductID="102" ProductColor="green" OrderQty="50"
RepName="Lois" OrderDate="2009-09-06"  />
<Sales ProductName="Thread" ProductID="102" ProductColor="blue" OrderQty="150"
RepName="George" OrderDate="2009-11-12"  />
</html>

Here is what you need to know:

  • The CSS selector syntax for extracting the value from a specific attribute is: tag::attribute(name).
  • Inside the parentheses, the attribute name should be set without spaces, i.e. tag::attribute(name), not tag::attribute( name ).
  • When a tag (<Sales> in the above example) with data inside it is an item, be sure to set it to type: item at the bottom of the <style> block.
  • If you plan to refer to the data from any of the columns, use the name property to specify a name for the column.
Example

Using the example data source above, to display the values of the attribute ProductName in column 1, OrderQty in column 2, and OrderDate in column 3, your <style> block would look like this:


<style>
    Sales::attribute(ProductName) { 
        itemcol: 1; 
        name: "products";
    }
    Sales::attribute(OrderQty)  {
        type: number;
        itemcol: 2;
        name: "quantity";
    }        
    Sales::attribute(OrderDate)  {
        type: date;
        itemcol: 3;
        name: "date";
    }        
    Sales   { 
        type: item; 
        definition: all;
    }
</style>

Note the use of the name property in each column. If you ever want to refer to any of the columns, such as from a column that displays the results of a mathematical formula, for specifying which columns to use in a chart or from the klipscript, you can use these names.

Also see: Appendix C in the Klip Developer Guide.

Leave a Comment

To leave a comment, you must sign in or register (it's free).

   
Comment Type:
Title:
Comment: