Liquid XML Studio
CodeToChar
See Also Send Feedback
Data Mapping > Data Mapper Functions > By Category > String > CodeToChar

Glossary Item Box

Function Name
CodeToChar
Category
String
Icon
CodeToChar
Description
Convert Unicode value to character
Inputs
Char Code Unicode representation of character
Outputs
Result Character represented by Unicode input
Properties
None -

Usage

The Data Mapper String CodeToChar function returns the character representation of a single Unicode value input. Often, XML data is mapped for use between differing Web and desktop applications, so the ability to convert data to different formats is essential. Converting Unicode to character data is therefore a useful facility. To apply the String CodeToChar transform 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 document_alt_source.xsd, an XML Schema Definition inferred from the following source:

Source XML Copy Code
<docs>
<document>
 <title>My Data File</title>
 <content>Here is my content</content>
 <type>98</type>
</document>
<document>
 <title>Another File</title>
 <content>Here is some more content</content>
 <type>114</type>
</document>
</docs>

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

Target XML Copy Code
<data_files>
 <file type="c" name="My File">Here is my content</file>
 <file type="s" name="His File">Here is his content</file>
</data_files>

The data models documents, with the "type" item using a single character. Here is the Data Mapper with Source and Target imported:

Data Mapper Source and Target

Drag the String CodeToChar function from the Component Palette into the mapping area:

String CodeToChar Component

String CodeToChar Transform Added

The String CodeToChar function takes a single input and gives a single output. The input should be connected to the source Unicode value to retrieve the character representation from. The output should be connected to the target item, whether an item in the XML Writer or another component in the Mapper. In this case we are mapping from an element in the source to an attribute in the target, converting to character at the same time. Connect the XML Reader "type" output to the CodeToChar input:

XML Reader to CodeToChar

Now connect the CodeToChar output to the "type" item in the XML Writer:

CodeToChar to XML Writer

Finally, connect the remaining inputs and outputs:

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_files>
 <file type="b" name="My Data File">Here is my content</file>
 <file type="r" name="Another File">Here is some more content</file>
</data_files>

The "type" items have been converted from Unicode to character data as part of the mapping process. The result is that the characters are now represented as text Strings rather than numerically.

This is a scalar function so the standard rules apply if multiple values are presented to one or more inputs.

See Also