Liquid Studio 2021
Data Mapping / Data Mapper Functions / By Category / Type / NodeType
In This Topic
    NodeType
    In This Topic

    Function Name
    Type
    Category
    Type
    Icon
    Type
    Description
    Retrieve the type of an input value
    Inputs
    Value Input value to determine type of
    Outputs
    Type Type of input value represented as String
    Properties
    None -

    Usage

    The Data Mapper Type function returns the type of a particular input value as a String. When mapping data, it is of course possible that your target application will not have awareness of the details of input data values, in which case you may need to determine data types before making use of your mapped values. The Type function can recognise various numerical types, booleans, Strings, binary/ bytes and date/ time types, as indicated in XSDs. To apply the Type function, use the following process:

    Create a new Data Mapper file, dragging your XML data source and targets into the editor area. For this example we are using value_types_source.xsd, an XML Schema Definition inferred from the following source:

    Source XML
    Copy Code
    <values>
     <section name="Objects">
      <item>Mat</item>
      <item>Hat</item>
      <item>Cat</item>
     </section>
     <section name="Colors">
      <item>Blue</item>
      <item>Green</item>
      <item>Yellow</item>
     </section>
    </values>
    

    For our target schema we will be using value_types_target.xsd, inferred from the following XML:

    Target XML
    Copy Code
    <data>
     <data_type>String</data_type>
     <category>
      <cat_name>People</cat_name>
      <value_item>Mary</value_item>
      <value_item>John</value_item>
     </category>
     <category>
      <cat_name>Places</cat_name>
      <value_item>London</value_item>
      <value_item>Paris</value_item>
     </category>
    </data>
    

    The data models values within sections, with the target including an element indicating the data types contained within the file. We are going to determine the type of the "item" element content, which in this case is String. The "data_type" element in the target will include an indicator of this data type. Here is the Data Mapper with Source and Target imported:

    Data Mapper Source and Target

    Drag the Type function from the Component Palette into the mapping area:

    Type Component

    Type Transform Added

    The Type function takes a single input and gives an output indicating the type in question. The input should be connected to the source item you want to determine type from. The output should be connected to the target item, whether an item in the XML Writer or another component in the Mapper.

    Connect the Type function output to the "data_type" input in the XML Writer.

    Type to Writer

    We have input data with multiple elements of the type we are interested in, so we only need one to determine the type from. To achieve this, let's drag a First function from the Set section of the Component Palette - this will return the first instance of the specified item within the source data. Connect the Nodes input of the First function to the "item" element in the XML Reader, since this is the element we are interested in.

    XML Reader to First

    This function will retrieve the first "item" element in the input data, so let's connect its output to the Value input of the Type function.

    First to Type

    Finally, connect the remaining inputs and outputs, remembering to map "item" to "value_item", meaning that the "item" output is connecting to two different inputs:

    Input and Output Connections Mapped

    We can now execute the transform by pressing Shift-F5 or the Execute button (Execute). The transform is applied and the file we selected as output opens in the editor:

    Output XML
    Copy Code
    <data>
     <data_type>String</data_type>
     <category>
      <cat_name>Objects</cat_name>
      <value_item>Mat</value_item>
      <value_item>Hat</value_item>
      <value_item>Cat</value_item>
     </category>
     <category>
      <cat_name>Colors</cat_name>
      <value_item>Blue</value_item>
      <value_item>Green</value_item>
      <value_item>Yellow</value_item>
     </category>
    </data>
    

    The type of the first "item" element has been mapped to the "data_type" element in the target as part of the mapping process. The result is that the output data now includes an indicator of the types of data item being handled.

    Possible output values of the Type function include: Binary, Boolean, Byte, DateTime, DateTimeOffset, Decimal, Double, Float, Guid, Int16, Int32, Int64, SByte, String, Time and Node.
    See Also